Answer the question
In order to leave comments, you need to log in
I have PHP code and I want it to look good. What to use for verification?
I have PHP code and I want it to look good. I heard that there are special programs that, according to certain standards, determine the quality code. What to use for verification?
<?php
require 'vendor/autoload.php';
$vk_config = array(
'app_id' => '3524816',
'api_secret' => 'JHHYnhMn9FxFAZfQYSlb',
'callback_url' => 'http://'.$_SERVER['HTTP_HOST'].'/',
'api_settings' => 'friends'
);
$app = new Silex\Application();
$app->get('/', function() use($app,$vk_config) {
$vk = new VK\VK($vk_config['app_id'], $vk_config['api_secret']);
try {
if (isset($_REQUEST['code'])) {
$access_token = $vk->getAccessToken($_REQUEST['code'], $vk_config['callback_url']);
return $app->json($access_token);
} else {
$authorize_url = $vk->getAuthorizeURL($vk_config['api_settings'], $vk_config['callback_url']);
return $app->json($authorize_url);
}
} catch (VK\VKException $e) {
return $app->json($e->getMessage());
}
});
$app->get('{user_id}/{access_token}', function($user_id,$access_token) use($app,$vk_config) {
$vk = new VK\VK($vk_config['app_id'], $vk_config['api_secret'], $access_token);
$online = $vk->api('friends.getOnline', array('user_id' => $user_id, 'online_mobile' => 1));
return $app->json($online);
});
$app->run();
Answer the question
In order to leave comments, you need to log in
Google psr-1 psr-2 standards, there are recommendations for php design (and in general read about everything from 0 to 4). In general, in phpstorm, for example, in the project settings, the desired formatting style is set (just the same psr-1/2) in the project properties and by pressing ctrl + alt + l the files themselves are brought to this formatting style.
looking good is one thing, but high-quality code is quite another
, as already written - for "looking good" you can use the ready-made psr standard
to analyze the quality of the code, there are phpmd, phploc, phpcpd ... but in any case, automatic code analysis will not tell how best to write it. it can only point out certain errors or give a signal that something is probably wrong somewhere
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question