Skip to content

Commit 243be0b

Browse files
committed
feature #397 Add PHP CS fixer for this application (bocharsky-bw)
This PR was squashed before being merged into the master branch (closes #397). Discussion ---------- Add PHP CS fixer for this application Resolve #395. Commits ------- d6a3492 Add PHP CS fixer for this application
2 parents 73ecd3c + d6a3492 commit 243be0b

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>

src/AppBundle/Controller/Admin/BlogController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* Please note that the application backend is developed manually for learning
2727
* purposes. However, in your real Symfony application you should use any of the
2828
* existing bundles that let you generate ready-to-use backends without effort.
29+
*
2930
* See http://knpbundles.com/keyword/admin
3031
*
3132
* @Route("/admin/post")
@@ -128,7 +129,7 @@ public function showAction(Post $post)
128129
$deleteForm = $this->createDeleteForm($post);
129130

130131
return $this->render('admin/blog/show.html.twig', [
131-
'post' => $post,
132+
'post' => $post,
132133
'delete_form' => $deleteForm->createView(),
133134
]);
134135
}
@@ -162,8 +163,8 @@ public function editAction(Post $post, Request $request)
162163
}
163164

164165
return $this->render('admin/blog/edit.html.twig', [
165-
'post' => $post,
166-
'edit_form' => $editForm->createView(),
166+
'post' => $post,
167+
'edit_form' => $editForm->createView(),
167168
'delete_form' => $deleteForm->createView(),
168169
]);
169170
}

src/AppBundle/Controller/BlogController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use AppBundle\Entity\Comment;
1515
use AppBundle\Entity\Post;
16+
use AppBundle\Form\CommentType;
1617
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
1718
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
1819
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
@@ -21,7 +22,6 @@
2122
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
2223
use Symfony\Component\HttpFoundation\Request;
2324
use Symfony\Component\HttpFoundation\Response;
24-
use AppBundle\Form\CommentType;
2525

2626
/**
2727
* Controller used to manage blog contents in the public part of the site.

src/AppBundle/Controller/SecurityController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
namespace AppBundle\Controller;
1313

14-
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
1514
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
15+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
1616

1717
/**
1818
* Controller used to manage the application security.

src/AppBundle/DataFixtures/ORM/LoadFixtures.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,19 @@
1111

1212
namespace AppBundle\DataFixtures\ORM;
1313

14-
use AppBundle\Entity\User;
15-
use AppBundle\Entity\Post;
1614
use AppBundle\Entity\Comment;
15+
use AppBundle\Entity\Post;
16+
use AppBundle\Entity\User;
1717
use Doctrine\Common\DataFixtures\FixtureInterface;
1818
use Doctrine\Common\Persistence\ObjectManager;
1919
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
2020
use Symfony\Component\DependencyInjection\ContainerInterface;
2121

2222
/**
2323
* Defines the sample data to load in the database when running the unit and
24-
* functional tests. Execute this command to load the data:
24+
* functional tests.
25+
*
26+
* Execute this command to load the data:
2527
*
2628
* $ php bin/console doctrine:fixtures:load
2729
*
@@ -106,7 +108,7 @@ public function setContainer(ContainerInterface $container = null)
106108

107109
private function getPostContent()
108110
{
109-
return <<<MARKDOWN
111+
return <<<'MARKDOWN'
110112
Lorem ipsum dolor sit amet consectetur adipisicing elit, sed do eiusmod tempor
111113
incididunt ut labore et **dolore magna aliqua**: Duis aute irure dolor in
112114
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
@@ -179,7 +181,7 @@ private function getRandomPostSummary($maxLength = 255)
179181
$numPhrases = mt_rand(6, 12);
180182
shuffle($phrases);
181183

182-
return substr(implode(' ', array_slice($phrases, 0, $numPhrases-1)), 0, $maxLength);
184+
return substr(implode(' ', array_slice($phrases, 0, $numPhrases - 1)), 0, $maxLength);
183185
}
184186

185187
private function getRandomCommentContent()
@@ -189,6 +191,6 @@ private function getRandomCommentContent()
189191
$numPhrases = mt_rand(2, 15);
190192
shuffle($phrases);
191193

192-
return implode(' ', array_slice($phrases, 0, $numPhrases-1));
194+
return implode(' ', array_slice($phrases, 0, $numPhrases - 1));
193195
}
194196
}

src/AppBundle/Entity/Post.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
namespace AppBundle\Entity;
44

5-
use Doctrine\ORM\Mapping as ORM;
65
use Doctrine\Common\Collections\ArrayCollection;
6+
use Doctrine\ORM\Mapping as ORM;
77
use Symfony\Component\Validator\Constraints as Assert;
88

99
/**
1010
* @ORM\Entity(repositoryClass="AppBundle\Repository\PostRepository")
1111
* @ORM\Table(name="symfony_demo_post")
1212
*
1313
* Defines the properties of the Post entity to represent the blog posts.
14+
*
1415
* See http://symfony.com/doc/current/book/doctrine.html#creating-an-entity-class
1516
*
1617
* Tip: if you have an existing database, you can generate these entity class automatically.
@@ -24,6 +25,7 @@ class Post
2425
/**
2526
* Use constants to define configuration options that rarely change instead
2627
* of specifying them in app/config/config.yml.
28+
*
2729
* See http://symfony.com/doc/current/best_practices/configuration.html#constants-vs-configuration-options
2830
*/
2931
const NUM_ITEMS = 10;

0 commit comments

Comments
 (0)