Skip to content

Add PHP CS fixer for this application #397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env php
<?php

$finder = Symfony\CS\Finder::create()
->ignoreDotFiles(true)
->ignoreVCS(true)
->exclude('app/config')
->exclude('app/data')
->exclude('app/Resources')
->exclude('var')
->exclude('vendor')
->exclude('web/bundles')
->exclude('web/css')
->exclude('web/fonts')
->exclude('web/js')
->notPath('web/config.php')
->in(__DIR__)
;

return Symfony\CS\Config::create()
->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL)
->fixers([
'-psr0', // Ignore Tests\ namespace prefix mismatch with tests/ directory
'ordered_use',
'phpdoc_order',
'short_array_syntax',
])
->finder($finder)
;
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ install:

script:
- ./vendor/bin/phpunit
- ./vendor/bin/php-cs-fixer fix --diff --dry-run -v
2 changes: 1 addition & 1 deletion app/AppKernel.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\HttpKernel\Kernel;

class AppKernel extends Kernel
{
Expand Down
6 changes: 2 additions & 4 deletions app/autoload.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?php

use Doctrine\Common\Annotations\AnnotationRegistry;
use Composer\Autoload\ClassLoader;
use Doctrine\Common\Annotations\AnnotationRegistry;

/**
* @var ClassLoader $loader
*/
/** @var ClassLoader $loader */
$loader = require __DIR__.'/../vendor/autoload.php';

AnnotationRegistry::registerLoader([$loader, 'loadClass']);
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"white-october/pagerfanta-bundle" : "^1.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer" : "^1.12",
"phpunit/phpunit" : "^4.8 || ^5.0",
"sensio/generator-bundle" : "^3.0",
"symfony/phpunit-bridge" : "^3.0"
Expand Down
62 changes: 60 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/AppBundle/AppBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

/**
* This class is the one that transforms the src/AppBundle/ directory into a real
* Symfony bundle. There are two types of bundles:
* Symfony bundle.
*
* There are two types of bundles:
*
* * Reusable Bundles: they are meant to be shared between different applications.
* A lot of them are even publicly available in sites like packagist.org.
Expand All @@ -37,7 +39,6 @@ class AppBundle extends Bundle
{
// At first it's common to leave this class empty, but when the application grows,
// you may need to add some initialization code in the boot() method.
//
// Checkout the Symfony\Component\HttpKernel\Bundle\Bundle class to see all
// the available methods for bundles.
}
9 changes: 5 additions & 4 deletions src/AppBundle/Command/AddUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@

namespace AppBundle\Command;

use AppBundle\Entity\User;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
use Doctrine\Common\Persistence\ObjectManager;
use AppBundle\Entity\User;

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

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

Expand Down Expand Up @@ -253,7 +254,7 @@ public function emailValidator($email)
*/
private function getCommandHelp()
{
return <<<HELP
return <<<'HELP'
The <info>%command.name%</info> command creates new users and saves them in the database:

<info>php %command.full_name%</info> <comment>username password email</comment>
Expand Down
6 changes: 4 additions & 2 deletions src/AppBundle/Command/DeleteUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,24 @@
namespace AppBundle\Command;

use AppBundle\Entity\User;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
use Doctrine\Common\Persistence\ObjectManager;

/**
* A command console that deletes users from the database.
*
* To use this command, open a terminal window, enter into your project
* directory and execute the following:
*
* $ php bin/console app:delete-user
*
* Check out the code of the src/AppBundle/Command/AddUserCommand.php file for
* the full explanation about Symfony commands.
*
* See http://symfony.com/doc/current/cookbook/console/console_command.html
*
* @author Oleg Voronkovich <[email protected]>
Expand All @@ -50,7 +52,7 @@ protected function configure()
->setName('app:delete-user')
->setDescription('Deletes users from the database')
->addArgument('username', InputArgument::REQUIRED, 'The username of an existing user')
->setHelp(<<<HELP
->setHelp(<<<'HELP'
The <info>%command.name%</info> command deletes users from the database:

<info>php %command.full_name%</info> <comment>username</comment>
Expand Down
10 changes: 6 additions & 4 deletions src/AppBundle/Command/ListUsersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\OutputInterface;

/**
* A command console that lists all the existing users. To use this command, open
* a terminal window, enter into your project directory and execute the following:
* A command console that lists all the existing users.
*
* To use this command, open a terminal window, enter into your project directory
* and execute the following:
*
* $ php bin/console app:list-users
*
Expand All @@ -46,7 +48,7 @@ protected function configure()
// a good practice is to use the 'app:' prefix to group all your custom application commands
->setName('app:list-users')
->setDescription('Lists all the existing users')
->setHelp(<<<HELP
->setHelp(<<<'HELP'
The <info>%command.name%</info> command lists all the users registered in the application:

<info>php %command.full_name%</info>
Expand Down
7 changes: 4 additions & 3 deletions src/AppBundle/Controller/Admin/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* Please note that the application backend is developed manually for learning
* purposes. However, in your real Symfony application you should use any of the
* existing bundles that let you generate ready-to-use backends without effort.
*
* See http://knpbundles.com/keyword/admin
*
* @Route("/admin/post")
Expand Down Expand Up @@ -128,7 +129,7 @@ public function showAction(Post $post)
$deleteForm = $this->createDeleteForm($post);

return $this->render('admin/blog/show.html.twig', [
'post' => $post,
'post' => $post,
'delete_form' => $deleteForm->createView(),
]);
}
Expand Down Expand Up @@ -162,8 +163,8 @@ public function editAction(Post $post, Request $request)
}

return $this->render('admin/blog/edit.html.twig', [
'post' => $post,
'edit_form' => $editForm->createView(),
'post' => $post,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/AppBundle/Controller/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use AppBundle\Entity\Comment;
use AppBundle\Entity\Post;
use AppBundle\Form\CommentType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
Expand All @@ -21,7 +22,6 @@
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use AppBundle\Form\CommentType;

/**
* Controller used to manage blog contents in the public part of the site.
Expand Down
2 changes: 1 addition & 1 deletion src/AppBundle/Controller/SecurityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

namespace AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

/**
* Controller used to manage the application security.
Expand Down
14 changes: 8 additions & 6 deletions src/AppBundle/DataFixtures/ORM/LoadFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@

namespace AppBundle\DataFixtures\ORM;

use AppBundle\Entity\User;
use AppBundle\Entity\Post;
use AppBundle\Entity\Comment;
use AppBundle\Entity\Post;
use AppBundle\Entity\User;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Defines the sample data to load in the database when running the unit and
* functional tests. Execute this command to load the data:
* functional tests.
*
* Execute this command to load the data:
*
* $ php bin/console doctrine:fixtures:load
*
Expand Down Expand Up @@ -106,7 +108,7 @@ public function setContainer(ContainerInterface $container = null)

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

return substr(implode(' ', array_slice($phrases, 0, $numPhrases-1)), 0, $maxLength);
return substr(implode(' ', array_slice($phrases, 0, $numPhrases - 1)), 0, $maxLength);
}

private function getRandomCommentContent()
Expand All @@ -189,6 +191,6 @@ private function getRandomCommentContent()
$numPhrases = mt_rand(2, 15);
shuffle($phrases);

return implode(' ', array_slice($phrases, 0, $numPhrases-1));
return implode(' ', array_slice($phrases, 0, $numPhrases - 1));
}
}
4 changes: 3 additions & 1 deletion src/AppBundle/Entity/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

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