Skip to content

Commit d6a3492

Browse files
bocharsky-bwjaviereguiluz
authored andcommitted
Add PHP CS fixer for this application
1 parent 665f1df commit d6a3492

31 files changed

+163
-64
lines changed

.php_cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
$finder = Symfony\CS\Finder::create()
5+
->ignoreDotFiles(true)
6+
->ignoreVCS(true)
7+
->exclude('app/config')
8+
->exclude('app/data')
9+
->exclude('app/Resources')
10+
->exclude('var')
11+
->exclude('vendor')
12+
->exclude('web/bundles')
13+
->exclude('web/css')
14+
->exclude('web/fonts')
15+
->exclude('web/js')
16+
->notPath('web/config.php')
17+
->in(__DIR__)
18+
;
19+
20+
return Symfony\CS\Config::create()
21+
->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL)
22+
->fixers([
23+
'-psr0', // Ignore Tests\ namespace prefix mismatch with tests/ directory
24+
'ordered_use',
25+
'phpdoc_order',
26+
'short_array_syntax',
27+
])
28+
->finder($finder)
29+
;

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ install:
2424

2525
script:
2626
- ./vendor/bin/phpunit
27+
- ./vendor/bin/php-cs-fixer fix --diff --dry-run -v

app/AppKernel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

3-
use Symfony\Component\HttpKernel\Kernel;
43
use Symfony\Component\Config\Loader\LoaderInterface;
4+
use Symfony\Component\HttpKernel\Kernel;
55

66
class AppKernel extends Kernel
77
{

app/autoload.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
<?php
22

3-
use Doctrine\Common\Annotations\AnnotationRegistry;
43
use Composer\Autoload\ClassLoader;
4+
use Doctrine\Common\Annotations\AnnotationRegistry;
55

6-
/**
7-
* @var ClassLoader $loader
8-
*/
6+
/** @var ClassLoader $loader */
97
$loader = require __DIR__.'/../vendor/autoload.php';
108

119
AnnotationRegistry::registerLoader([$loader, 'loadClass']);

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"white-october/pagerfanta-bundle" : "^1.0"
3030
},
3131
"require-dev": {
32+
"friendsofphp/php-cs-fixer" : "^1.12",
3233
"phpunit/phpunit" : "^4.8 || ^5.0",
3334
"sensio/generator-bundle" : "^3.0",
3435
"symfony/phpunit-bridge" : "^3.0"

composer.lock

Lines changed: 60 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/AppBundle/AppBundle.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616
/**
1717
* This class is the one that transforms the src/AppBundle/ directory into a real
18-
* Symfony bundle. There are two types of bundles:
18+
* Symfony bundle.
19+
*
20+
* There are two types of bundles:
1921
*
2022
* * Reusable Bundles: they are meant to be shared between different applications.
2123
* A lot of them are even publicly available in sites like packagist.org.
@@ -37,7 +39,6 @@ class AppBundle extends Bundle
3739
{
3840
// At first it's common to leave this class empty, but when the application grows,
3941
// you may need to add some initialization code in the boot() method.
40-
//
4142
// Checkout the Symfony\Component\HttpKernel\Bundle\Bundle class to see all
4243
// the available methods for bundles.
4344
}

src/AppBundle/Command/AddUserCommand.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@
1111

1212
namespace AppBundle\Command;
1313

14+
use AppBundle\Entity\User;
15+
use Doctrine\Common\Persistence\ObjectManager;
1416
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
1517
use Symfony\Component\Console\Input\InputArgument;
1618
use Symfony\Component\Console\Input\InputInterface;
1719
use Symfony\Component\Console\Input\InputOption;
1820
use Symfony\Component\Console\Output\OutputInterface;
1921
use Symfony\Component\Console\Question\Question;
20-
use Doctrine\Common\Persistence\ObjectManager;
21-
use AppBundle\Entity\User;
2222

2323
/**
2424
* A command console that creates users and stores them in the database.
25+
*
2526
* To use this command, open a terminal window, enter into your project
2627
* directory and execute the following:
2728
*
@@ -204,7 +205,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
204205
$finishTime = microtime(true);
205206
$elapsedTime = $finishTime - $startTime;
206207

207-
$output->writeln(sprintf('[INFO] New user database id: %d / Elapsed time: %.2f ms', $user->getId(), $elapsedTime*1000));
208+
$output->writeln(sprintf('[INFO] New user database id: %d / Elapsed time: %.2f ms', $user->getId(), $elapsedTime * 1000));
208209
}
209210
}
210211

@@ -253,7 +254,7 @@ public function emailValidator($email)
253254
*/
254255
private function getCommandHelp()
255256
{
256-
return <<<HELP
257+
return <<<'HELP'
257258
The <info>%command.name%</info> command creates new users and saves them in the database:
258259
259260
<info>php %command.full_name%</info> <comment>username password email</comment>

src/AppBundle/Command/DeleteUserCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,24 @@
1212
namespace AppBundle\Command;
1313

1414
use AppBundle\Entity\User;
15+
use Doctrine\Common\Persistence\ObjectManager;
1516
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
1617
use Symfony\Component\Console\Input\InputArgument;
1718
use Symfony\Component\Console\Input\InputInterface;
1819
use Symfony\Component\Console\Output\OutputInterface;
1920
use Symfony\Component\Console\Question\Question;
20-
use Doctrine\Common\Persistence\ObjectManager;
2121

2222
/**
2323
* A command console that deletes users from the database.
24+
*
2425
* To use this command, open a terminal window, enter into your project
2526
* directory and execute the following:
2627
*
2728
* $ php bin/console app:delete-user
2829
*
2930
* Check out the code of the src/AppBundle/Command/AddUserCommand.php file for
3031
* the full explanation about Symfony commands.
32+
*
3133
* See http://symfony.com/doc/current/cookbook/console/console_command.html
3234
*
3335
* @author Oleg Voronkovich <[email protected]>
@@ -50,7 +52,7 @@ protected function configure()
5052
->setName('app:delete-user')
5153
->setDescription('Deletes users from the database')
5254
->addArgument('username', InputArgument::REQUIRED, 'The username of an existing user')
53-
->setHelp(<<<HELP
55+
->setHelp(<<<'HELP'
5456
The <info>%command.name%</info> command deletes users from the database:
5557
5658
<info>php %command.full_name%</info> <comment>username</comment>

src/AppBundle/Command/ListUsersCommand.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
use Symfony\Component\Console\Helper\Table;
1818
use Symfony\Component\Console\Input\InputInterface;
1919
use Symfony\Component\Console\Input\InputOption;
20-
use Symfony\Component\Console\Output\OutputInterface;
2120
use Symfony\Component\Console\Output\BufferedOutput;
21+
use Symfony\Component\Console\Output\OutputInterface;
2222

2323
/**
24-
* A command console that lists all the existing users. To use this command, open
25-
* a terminal window, enter into your project directory and execute the following:
24+
* A command console that lists all the existing users.
25+
*
26+
* To use this command, open a terminal window, enter into your project directory
27+
* and execute the following:
2628
*
2729
* $ php bin/console app:list-users
2830
*
@@ -46,7 +48,7 @@ protected function configure()
4648
// a good practice is to use the 'app:' prefix to group all your custom application commands
4749
->setName('app:list-users')
4850
->setDescription('Lists all the existing users')
49-
->setHelp(<<<HELP
51+
->setHelp(<<<'HELP'
5052
The <info>%command.name%</info> command lists all the users registered in the application:
5153
5254
<info>php %command.full_name%</info>

0 commit comments

Comments
 (0)