Skip to content

Commit

Permalink
[cs] apply clean-code set
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Dec 9, 2019
1 parent 9103106 commit cfcc179
Show file tree
Hide file tree
Showing 30 changed files with 54 additions and 159 deletions.
2 changes: 1 addition & 1 deletion ecs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ parameters:
- 'php71'
# - 'symplify'
# - 'common'
# - 'clean-code'
- 'clean-code'

skip:
PhpCsFixer\Fixer\Operator\UnaryOperatorSpacesFixer: null
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Knp\DoctrineBehaviors\Bundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
Expand Down
6 changes: 3 additions & 3 deletions src/Model/Blameable/BlameableMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
trait BlameableMethods
{
/**
* @param mixed the user representation
* @param mixed $user the user representation
* @return $this
*/
public function setCreatedBy($user)
Expand All @@ -32,7 +32,7 @@ public function setCreatedBy($user)
}

/**
* @param mixed the user representation
* @param mixed $user the user representation
* @return $this
*/
public function setUpdatedBy($user)
Expand All @@ -43,7 +43,7 @@ public function setUpdatedBy($user)
}

/**
* @param mixed the user representation
* @param mixed $user the user representation
* @return $this
*/
public function setDeletedBy($user)
Expand Down
2 changes: 0 additions & 2 deletions src/Model/Geocodable/Geocodable.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

namespace Knp\DoctrineBehaviors\Model\Geocodable;

use Knp\DoctrineBehaviors\ORM\Geocodable\Type\Point;

/**
* Geocodable trait.
*
Expand Down
2 changes: 0 additions & 2 deletions src/Model/Geocodable/GeocodableProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

namespace Knp\DoctrineBehaviors\Model\Geocodable;

use Knp\DoctrineBehaviors\ORM\Geocodable\Type\Point;

/**
* Geocodable trait.
*
Expand Down
8 changes: 3 additions & 5 deletions src/Model/Sluggable/SluggableMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function setSlug($slug)

return $this;
}

/**
* Returns the entity's slug.
*
Expand All @@ -74,7 +74,7 @@ public function getSlug()
private function generateSlugValue($values)
{
$usableValues = [];
foreach ($values as $fieldName => $fieldValue) {
foreach ($values as $fieldValue) {
if (!empty($fieldValue)) {
$usableValues[] = $fieldValue;
}
Expand All @@ -93,9 +93,7 @@ private function generateSlugValue($values)
$sluggableText = $transliterator->transliterate($sluggableText, $this->getSlugDelimiter());

$urlized = strtolower(trim(preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $sluggableText), $this->getSlugDelimiter()));
$urlized = preg_replace("/[\/_|+ -]+/", $this->getSlugDelimiter(), $urlized);

return $urlized;
return preg_replace("/[\/_|+ -]+/", $this->getSlugDelimiter(), $urlized);
}

/**
Expand Down
13 changes: 4 additions & 9 deletions src/Model/Tree/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,18 @@

use Doctrine\Common\Collections\ArrayCollection;

use Doctrine\Common\Collections\Collection;
use Knp\DoctrineBehaviors\Model\Tree\NodeInterface;

/*
* @author Florian Klein <florian.klein@free.fr>
*/
trait Node
{
/**
* @var ArrayCollection $childNodes the children in the tree
* @var ArrayCollection the children in the tree
*/
private $childNodes;

/**
* @var NodeInterface $parentNode the parent in the tree
* @var NodeInterface the parent in the tree
*/
private $parentNode;

Expand Down Expand Up @@ -82,9 +79,7 @@ public function getParentMaterializedPath()
$path = $this->getExplodedPath();
array_pop($path);

$parentPath = static::getMaterializedPathSeparator() . implode(static::getMaterializedPathSeparator(), $path);

return $parentPath;
return static::getMaterializedPathSeparator() . implode(static::getMaterializedPathSeparator(), $path);
}

/**
Expand Down Expand Up @@ -227,7 +222,7 @@ public function getRootNode()
public function buildTree(array $results): void
{
$this->getChildNodes()->clear();
foreach ($results as $i => $node) {
foreach ($results as $node) {
if ($node->getMaterializedPath() === $this->getRealMaterializedPath()) {
$node->setParentNode($this);
$node->buildTree($results);
Expand Down
9 changes: 2 additions & 7 deletions src/ORM/Blameable/BlameableSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@

namespace Knp\DoctrineBehaviors\ORM\Blameable;

use Doctrine\Common\EventSubscriber;

use Doctrine\Common\Persistence\Mapping\ClassMetadata;

use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Doctrine\ORM\Event\OnFlushEventArgs;

use Doctrine\ORM\Events,
Knp\DoctrineBehaviors\ORM\AbstractSubscriber,
Expand Down Expand Up @@ -50,7 +47,7 @@ class BlameableSubscriber extends AbstractSubscriber
private $blameableTrait;

/**
* @param callable
* @param callable $classAnalyzer
* @param string $userEntity
*/
public function __construct(ClassAnalyzer $classAnalyzer, $isRecursive, $blameableTrait, ?callable $userCallable = null, $userEntity = null)
Expand Down Expand Up @@ -290,14 +287,12 @@ public function getUser()

public function getSubscribedEvents()
{
$events = [
return [
Events::prePersist,
Events::preUpdate,
Events::preRemove,
Events::loadClassMetadata,
];

return $events;
}

public function setUserCallable(callable $callable): void
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/Blameable/UserCallable.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class UserCallable
private $container;

/**
* @param callable
* @param callable $container
* @param string $userEntity
*/
public function __construct(Container $container)
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/Filterable/FilterableRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ abstract public function getInFilterColumns();
* Filter values
*
* @param array $filters - array like ['e:name' => 'nameValue'] where "e" is entity alias query, so we can filter using joins.
* @param \Doctrine\ORM\QueryBuilder
* @param \Doctrine\ORM\QueryBuilder $qb
* @return \Doctrine\ORM\QueryBuilder
*/
public function filterBy(array $filters, ?QueryBuilder $qb = null)
Expand Down
3 changes: 0 additions & 3 deletions src/ORM/Geocodable/GeocodableSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

namespace Knp\DoctrineBehaviors\ORM\Geocodable;

use Doctrine\Common\EventSubscriber;

use Doctrine\Common\Persistence\Mapping\ClassMetadata;

use Doctrine\DBAL\Platforms\MySqlPlatform;
Expand All @@ -23,7 +21,6 @@
use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Doctrine\ORM\Event\OnFlushEventArgs;
use Doctrine\ORM\Events;

use Knp\DoctrineBehaviors\ORM\AbstractSubscriber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Knp\DoctrineBehaviors\ORM\Geocodable\Query\AST\Functions;

use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\AST\PathExpression;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;
Expand Down
4 changes: 1 addition & 3 deletions src/ORM/Joinable/JoinableRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ private function addJoinsToQueryBuilder($alias, QueryBuilder $qb, $className, $r
private function getAlias($className)
{
$shortName = $this->getEntityManager()->getClassMetadata($className)->reflClass->getShortName();
$alias = strtolower(substr($shortName, 0, 1));

return $alias;
return strtolower(substr($shortName, 0, 1));
}

private function getUniqueAlias($className, QueryBuilder $qb)
Expand Down
9 changes: 2 additions & 7 deletions src/ORM/Loggable/LoggableSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@

namespace Knp\DoctrineBehaviors\ORM\Loggable;

use Doctrine\Common\EventSubscriber;

use Doctrine\ORM\Event\LifecycleEventArgs;

use Doctrine\ORM\Event\OnFlushEventArgs;

use Doctrine\ORM\Events,
Knp\DoctrineBehaviors\ORM\AbstractSubscriber,
Expand All @@ -35,7 +32,7 @@ class LoggableSubscriber extends AbstractSubscriber
private $loggerCallable;

/**
* @param callable
* @param callable $classAnalyzer
*/
public function __construct(ClassAnalyzer $classAnalyzer, $isRecursive, callable $loggerCallable)
{
Expand Down Expand Up @@ -116,12 +113,10 @@ protected function isEntitySupported(\ReflectionClass $reflClass)

public function getSubscribedEvents()
{
$events = [
return [
Events::postPersist,
Events::postUpdate,
Events::preRemove,
];

return $events;
}
}
1 change: 0 additions & 1 deletion src/ORM/Sluggable/SluggableSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace Knp\DoctrineBehaviors\ORM\Sluggable;

use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\LifecycleEventArgs;

use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
Expand Down
2 changes: 0 additions & 2 deletions src/ORM/SoftDeletable/SoftDeletableSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

namespace Knp\DoctrineBehaviors\ORM\SoftDeletable;

use Doctrine\Common\EventSubscriber;

use Doctrine\Common\Persistence\Mapping\ClassMetadata;

use Doctrine\ORM\Event\LoadClassMetadataEventArgs,
Expand Down
1 change: 0 additions & 1 deletion src/ORM/Translatable/CurrentLocaleCallable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Knp\DoctrineBehaviors\ORM\Translatable;

use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\Request;

/**
* @author Florian Klein <florian.klein@free.fr>
Expand Down
2 changes: 0 additions & 2 deletions src/ORM/Translatable/DefaultLocaleCallable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Knp\DoctrineBehaviors\ORM\Translatable;

use Symfony\Component\DependencyInjection\Container;

/**
* @author Jérôme Fix <jerome.fix@zapoyok.info>
*/
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/Translatable/TranslatableSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private function mapId(ClassMetadata $class, EntityManager $em): void
$sequenceName = $em->getConfiguration()->getQuoteStrategy()->getSequenceName($definition, $class, $platform);
}

$generator = ($fieldName && $class->fieldMappings[$fieldName]['type'] === 'bigint')
$generator = $fieldName && $class->fieldMappings[$fieldName]['type'] === 'bigint'
? new BigIntegerIdentityGenerator($sequenceName)
: new IdentityGenerator($sequenceName);

Expand Down
2 changes: 0 additions & 2 deletions src/Reflection/ClassAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

namespace Knp\DoctrineBehaviors\Reflection;

use Doctrine\Common\EventSubscriber;

class ClassAnalyzer
{
/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Knp/DoctrineBehaviors/ORM/GeocodableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GeocodableTest extends \PHPUnit_Framework_TestCase
use EntityManagerProvider;

/**
* @var callable $callable
* @var callable
*/
private $callable;

Expand Down Expand Up @@ -73,7 +73,7 @@ public function setUp(): void
$entity = new GeocodableEntity($city[1][0], $city[1][1]);
$entity->setTitle($city[0]);
$em->persist($entity);
};
}

$em->flush();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Knp/DoctrineBehaviors/ORM/TranslatableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function should_update_and_add_new_translations(): void
*/
public function translate_method_should_always_return_translation_object(): void
{
$em = $this->getEntityManager();
$this->getEntityManager();

$entity = new \BehaviorFixtures\ORM\TranslatableEntity();

Expand Down Expand Up @@ -269,7 +269,7 @@ public function should_have_oneToMany_relation_when_translation_class_name_is_cu
*/
public function should_create_only_one_time_the_same_translation(): void
{
$em = $this->getEntityManager();
$this->getEntityManager();

$entity = new \BehaviorFixtures\ORM\TranslatableEntity();
$translation = $entity->translate('fr');
Expand Down
4 changes: 1 addition & 3 deletions tests/Knp/DoctrineBehaviors/ORM/Tree/NodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function provideisChildNodeOf()

public function provideToArray()
{
$expected = [
return [
1 =>
[
'node' => '',
Expand Down Expand Up @@ -195,8 +195,6 @@ public function provideToArray()
],
],
];

return $expected;
}

public function testToArray(): void
Expand Down
Loading

0 comments on commit cfcc179

Please sign in to comment.