Skip to content

Commit

Permalink
Merge pull request #19 from peter-gribanov/php-cs-fixer
Browse files Browse the repository at this point in the history
Add php-cs-fixer to control the code style during development
  • Loading branch information
peter-gribanov committed Oct 30, 2019
2 parents 3f47c94 + 49a4c1a commit 46bde75
Show file tree
Hide file tree
Showing 25 changed files with 72 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
/build/
phpunit.xml
composer.lock
.php_cs
.php_cs.cache
29 changes: 29 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
$header = <<<EOF
GpsLab component.
@author Peter Gribanov <info@peter-gribanov.ru>
@copyright Copyright (c) 2011, Peter Gribanov
@license http://opensource.org/licenses/MIT
EOF;

return PhpCsFixer\Config::create()
->setRules([
'@Symfony' => true,
'header_comment' => [
'comment_type' => 'PHPDoc',
'header' => $header,
],
'array_syntax' => ['syntax' => 'short'],
'yoda_style' => false,
'ordered_imports' => [
'sort_algorithm' => 'alpha',
],
])
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__.'/src')
->in(__DIR__.'/tests')
->notPath('bootstrap.php')
)
;
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"require-dev": {
"phpunit/phpunit": "~4.8",
"scrutinizer/ocular": "~1.3",
"satooshi/php-coveralls": "^1.0"
"satooshi/php-coveralls": "^1.0",
"friendsofphp/php-cs-fixer": "~2.2"
}
}
1 change: 1 addition & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* GpsLab component.
*
Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/GpsLabPaginationExtension.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* GpsLab component.
*
Expand Down
1 change: 1 addition & 0 deletions src/Entity/Node.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* GpsLab component.
*
Expand Down
1 change: 1 addition & 0 deletions src/Exception/IncorrectPageNumberException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* GpsLab component.
*
Expand Down
1 change: 1 addition & 0 deletions src/Exception/OutOfRangeException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* GpsLab component.
*
Expand Down
1 change: 1 addition & 0 deletions src/GpsLabPaginationBundle.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* GpsLab component.
*
Expand Down
14 changes: 10 additions & 4 deletions src/Service/Builder.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* GpsLab component.
*
Expand All @@ -9,9 +10,10 @@

namespace GpsLab\Bundle\PaginationBundle\Service;

use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\QueryBuilder;
use GpsLab\Bundle\PaginationBundle\Exception\IncorrectPageNumberException;
use GpsLab\Bundle\PaginationBundle\Exception\OutOfRangeException;
use Doctrine\ORM\QueryBuilder;
use Symfony\Bundle\FrameworkBundle\Routing\Router;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
Expand All @@ -28,14 +30,14 @@ class Builder
*
* @var int
*/
private $max_navigate = Configuration::DEFAULT_LIST_LENGTH;
private $max_navigate;

/**
* Name of URL parameter for page number.
*
* @var string
*/
private $parameter_name = 'page';
private $parameter_name;

/**
* @param Router $router Router service
Expand Down Expand Up @@ -68,6 +70,8 @@ public function paginate($total_pages = 1, $current_page = 1)
* @param int $per_page Entities per page
* @param int $current_page The current page number
*
* @throws NonUniqueResultException
*
* @return Configuration
*/
public function paginateQuery(QueryBuilder $query, $per_page, $current_page = 1)
Expand Down Expand Up @@ -122,6 +126,8 @@ public function paginateRequest(
* @param string $parameter_name Name of URL parameter for page number
* @param int $reference_type The type of reference (one of the constants in UrlGeneratorInterface)
*
* @throws NonUniqueResultException
*
* @return Configuration
*/
public function paginateRequestQuery(
Expand Down Expand Up @@ -149,7 +155,7 @@ public function paginateRequestQuery(
*/
private function validateCurrentPage($current_page, $total_pages)
{
if (is_null($current_page)) {
if ($current_page === null) {
return 1;
}

Expand Down
1 change: 1 addition & 0 deletions src/Service/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* GpsLab component.
*
Expand Down
1 change: 1 addition & 0 deletions src/Service/NavigateRange.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* GpsLab component.
*
Expand Down
11 changes: 6 additions & 5 deletions src/Service/View.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* GpsLab component.
*
Expand All @@ -9,8 +10,8 @@

namespace GpsLab\Bundle\PaginationBundle\Service;

use GpsLab\Bundle\PaginationBundle\Entity\Node;
use Doctrine\Common\Collections\ArrayCollection;
use GpsLab\Bundle\PaginationBundle\Entity\Node;

class View implements \IteratorAggregate
{
Expand Down Expand Up @@ -159,7 +160,7 @@ public function getIterator()
$this->list->add(new Node(
$page,
$this->buildLink($page),
$page == $this->config->getCurrentPage()
$page === $this->config->getCurrentPage()
));
++$page;
}
Expand All @@ -176,14 +177,14 @@ public function getIterator()
*/
private function buildLink($page)
{
if ($page == 1 && $this->config->getFirstPageLink()) {
if ($page === 1 && $this->config->getFirstPageLink()) {
return $this->config->getFirstPageLink();
}

if (is_callable($this->config->getPageLink())) {
return call_user_func($this->config->getPageLink(), $page);
} else {
return sprintf($this->config->getPageLink(), $page);
}

return sprintf($this->config->getPageLink(), $page);
}
}
1 change: 1 addition & 0 deletions src/Twig/Extension/PaginationExtension.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* GpsLab component.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* GpsLab component.
*
Expand Down
1 change: 1 addition & 0 deletions tests/Entity/NodeTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* GpsLab component.
*
Expand Down
1 change: 1 addition & 0 deletions tests/Exception/IncorrectPageNumberExceptionTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* GpsLab component.
*
Expand Down
1 change: 1 addition & 0 deletions tests/Exception/OutOfRangeExceptionTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* GpsLab component.
*
Expand Down
1 change: 1 addition & 0 deletions tests/GpsLabPaginationBundleTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* GpsLab component.
*
Expand Down
3 changes: 2 additions & 1 deletion tests/Service/BuilderTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* GpsLab component.
*
Expand All @@ -9,9 +10,9 @@

namespace GpsLab\Bundle\PaginationBundle\Tests\Service;

use GpsLab\Bundle\PaginationBundle\Service\Builder;
use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\QueryBuilder;
use GpsLab\Bundle\PaginationBundle\Service\Builder;
use GpsLab\Bundle\PaginationBundle\Tests\TestCase;
use Symfony\Bundle\FrameworkBundle\Routing\Router;
use Symfony\Component\HttpFoundation\ParameterBag;
Expand Down
1 change: 1 addition & 0 deletions tests/Service/ConfigurationTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* GpsLab component.
*
Expand Down
1 change: 1 addition & 0 deletions tests/Service/NavigateRangeTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* GpsLab component.
*
Expand Down
5 changes: 3 additions & 2 deletions tests/Service/ViewTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* GpsLab component.
*
Expand All @@ -9,11 +10,11 @@

namespace GpsLab\Bundle\PaginationBundle\Tests\Service;

use Doctrine\Common\Collections\ArrayCollection;
use GpsLab\Bundle\PaginationBundle\Entity\Node;
use GpsLab\Bundle\PaginationBundle\Service\Configuration;
use GpsLab\Bundle\PaginationBundle\Service\NavigateRange;
use GpsLab\Bundle\PaginationBundle\Service\View;
use Doctrine\Common\Collections\ArrayCollection;
use GpsLab\Bundle\PaginationBundle\Tests\TestCase;

class ViewTest extends TestCase
Expand Down Expand Up @@ -373,7 +374,7 @@ public function testGetIterator($total_pages, $page_link, $first_page_link, $lis
$left_offset = $current_page - $list->first()->getPage();
$right_offset = $list->last()->getPage() - $current_page;

if ($list->first()->getPage() == 1) {
if ($list->first()->getPage() === 1) {
$this->config
->expects($this->once())
->method('getFirstPageLink')
Expand Down
1 change: 1 addition & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* GpsLab component.
*
Expand Down
1 change: 1 addition & 0 deletions tests/Twig/Extension/PaginationExtensionTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* GpsLab component.
*
Expand Down

0 comments on commit 46bde75

Please sign in to comment.