K
K
krll-k2014-08-24 18:05:36
PHP
krll-k, 2014-08-24 18:05:36

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();

Sorry, but not everyone has PhpStorm, and I would write a Phing script that would check the code against the standard before building

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Evgrafovich, 2014-08-24
@Tantacula

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.

1
1Michael1, 2014-08-24
@1Michael1

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

A
Alex, 2014-08-24
@sensus

framework.zend.com/manual/1.10/en/coding-standard....
If you're using phpstorm, highlight the code you want to spice up, and choose:
or just press Ctrl+Alt+L

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question