Skip to content

Commit

Permalink
[cs] apply symplify set
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Dec 10, 2019
1 parent b44fe96 commit 2d22250
Show file tree
Hide file tree
Showing 58 changed files with 1,076 additions and 1,210 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"phpunit/phpunit": "^8.5",
"jakub-onderka/php-parallel-lint": "^1.0",
"symplify/easy-coding-standard": "^7.1",
"phpstan/phpstan": "^0.12.2"
"phpstan/phpstan": "^0.12.2",
"doctrine/annotations": "^1.8"
},
"autoload": {
"psr-4": {
Expand Down
18 changes: 17 additions & 1 deletion ecs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,28 @@ parameters:
- 'psr12'
- 'php70'
- 'php71'
# - 'symplify'
- 'symplify'
- 'common'
- 'clean-code'

skip:
PhpCsFixer\Fixer\Operator\UnaryOperatorSpacesFixer: null
Symplify\CodingStandard\Sniffs\ControlStructure\SprintfOverContactSniff: null
Symplify\CodingStandard\Sniffs\Naming\TraitNameSniff: null
Symplify\CodingStandard\Sniffs\CleanCode\ForbiddenStaticFunctionSniff: null
Symplify\CodingStandard\Sniffs\CleanCode\CognitiveComplexitySniff: null
Symplify\CodingStandard\Sniffs\CleanCode\ForbiddenReferenceSniff: null
Symplify\CodingStandard\Sniffs\Architecture\ExplicitExceptionSniff: null
Symplify\CodingStandard\Sniffs\Architecture\DuplicatedClassShortNameSniff: null

# buggy
Symplify\CodingStandard\Fixer\ControlStructure\PregDelimiterFixer: null

SlevomatCodingStandard\Sniffs\Namespaces\ReferenceUsedNamesOnlySniff.PartialUse:
- 'tests/Fixtures/BehaviorFixtures/ORM/FilterableRepository.php'

SlevomatCodingStandard\Sniffs\Namespaces\ReferenceUsedNamesOnlySniff.ReferenceViaFullyQualifiedName:
- 'src/Model/Sluggable/Transliterator.php'

services:
# see single LICENSE.txt file in the root directory
Expand Down
2 changes: 1 addition & 1 deletion src/Bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
final class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
Expand Down
6 changes: 3 additions & 3 deletions src/Bundle/DependencyInjection/DoctrineBehaviorsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

class DoctrineBehaviorsExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container): void
public function load(array $configs, ContainerBuilder $containerBuilder): void
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../../../config'));
$loader = new YamlFileLoader($containerBuilder, new FileLocator(__DIR__ . '/../../../config'));
$loader->load('orm-services.yml');

$configuration = new Configuration();
Expand All @@ -25,7 +25,7 @@ public function load(array $configs, ContainerBuilder $container): void

foreach ($config as $behavior => $enabled) {
if (! $enabled) {
$container->removeDefinition(sprintf('knp.doctrine_behaviors.%s_subscriber', $behavior));
$containerBuilder->removeDefinition(sprintf('knp.doctrine_behaviors.%s_subscriber', $behavior));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/DBAL/Types/PointType.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform)

/**
* @param string $sqlExpr
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
* @param AbstractPlatform $platform
*
* @return string
*/
Expand Down
3 changes: 0 additions & 3 deletions src/Model/Blameable/BlameableMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ trait BlameableMethods
{
/**
* @param mixed $user the user representation
* @return $this
*/
public function setCreatedBy($user)
{
Expand All @@ -19,7 +18,6 @@ public function setCreatedBy($user)

/**
* @param mixed $user the user representation
* @return $this
*/
public function setUpdatedBy($user)
{
Expand All @@ -30,7 +28,6 @@ public function setUpdatedBy($user)

/**
* @param mixed $user the user representation
* @return $this
*/
public function setDeletedBy($user)
{
Expand Down
18 changes: 3 additions & 15 deletions src/Model/Geocodable/GeocodableMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,14 @@

trait GeocodableMethods
{
/**
* Get location.
*
* @return Point.
*/
public function getLocation()
public function getLocation(): Point
{
return $this->location;
}

/**
* Set location.
*
* @param Point|null $location the value to set.
*
* @return $this
*/
public function setLocation(?Point $location = null)
public function setLocation(?Point $point = null)
{
$this->location = $location;
$this->location = $point;

return $this;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Model/Loggable/Loggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Knp\DoctrineBehaviors\Model\Loggable;

use DateTime;

trait Loggable
{
/**
Expand All @@ -14,7 +16,7 @@ public function getUpdateLogMessage(array $changeSets = [])
$message = [];
foreach ($changeSets as $property => $changeSet) {
for ($i = 0, $s = sizeof($changeSet); $i < $s; $i++) {
if ($changeSet[$i] instanceof \DateTime) {
if ($changeSet[$i] instanceof DateTime) {
$changeSet[$i] = $changeSet[$i]->format('Y-m-d H:i:s.u');
}
}
Expand Down
14 changes: 10 additions & 4 deletions src/Model/Sluggable/SluggableMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Knp\DoctrineBehaviors\Model\Sluggable;

use UnexpectedValueException;

trait SluggableMethods
{
/**
Expand All @@ -17,7 +19,6 @@ abstract public function getSluggableFields();
* Sets the entity's slug.
*
* @param $slug
* @return $this
*/
public function setSlug($slug)
{
Expand Down Expand Up @@ -98,8 +99,11 @@ private function generateSlugValue($values)
}

if (count($usableValues) < 1) {
throw new \UnexpectedValueException(
'Sluggable expects to have at least one usable (non-empty) field from the following: [ ' . implode(array_keys($values), ',') . ' ]'
throw new UnexpectedValueException(
'Sluggable expects to have at least one usable (non-empty) field from the following: [ ' . implode(
array_keys($values),
','
) . ' ]'
);
}

Expand All @@ -109,7 +113,9 @@ private function generateSlugValue($values)
$transliterator = new Transliterator();
$sluggableText = $transliterator->transliterate($sluggableText, $this->getSlugDelimiter());

$urlized = strtolower(trim(preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $sluggableText), $this->getSlugDelimiter()));
$urlized = strtolower(
trim(preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $sluggableText), $this->getSlugDelimiter())
);
return preg_replace("/[\/_|+ -]+/", $this->getSlugDelimiter(), $urlized);
}
}
49 changes: 11 additions & 38 deletions src/Model/SoftDeletable/SoftDeletableMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

namespace Knp\DoctrineBehaviors\Model\SoftDeletable;

use DateTime;
use DateTimeInterface;
use DateTimeZone;

trait SoftDeletableMethods
{
/**
* Marks entity as deleted.
*/
public function delete(): void
{
$this->deletedAt = $this->currentDateTime();
Expand All @@ -22,12 +23,7 @@ public function restore(): void
$this->deletedAt = null;
}

/**
* Checks whether the entity has been deleted.
*
* @return boolean
*/
public function isDeleted()
public function isDeleted(): bool
{
if ($this->deletedAt !== null) {
return $this->deletedAt <= $this->currentDateTime();
Expand All @@ -36,12 +32,7 @@ public function isDeleted()
return false;
}

/**
* Checks whether the entity will be deleted.
*
* @return boolean
*/
public function willBeDeleted(?\DateTime $at = null)
public function willBeDeleted(?DateTime $at = null): bool
{
if ($this->deletedAt === null) {
return false;
Expand All @@ -53,40 +44,22 @@ public function willBeDeleted(?\DateTime $at = null)
return $this->deletedAt <= $at;
}

/**
* Returns date on which entity was been deleted.
*
* @return DateTime|null
*/
public function getDeletedAt()
public function getDeletedAt(): ?DateTimeInterface
{
return $this->deletedAt;
}

/**
* Set the delete date to given date.
*
* @param DateTime $date
* @param object
*
* @return $this
*/
public function setDeletedAt(\DateTime $date)
public function setDeletedAt(DateTime $date)
{
$this->deletedAt = $date;

return $this;
}

/**
* Get a instance of \DateTime with the current data time including milliseconds.
*
* @return \DateTime
*/
private function currentDateTime()
private function currentDateTime(): ?DateTimeInterface
{
$dateTime = \DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)));
$dateTime->setTimezone(new \DateTimeZone(date_default_timezone_get()));
$dateTime = DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)));
$dateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));

return $dateTime;
}
Expand Down
5 changes: 0 additions & 5 deletions src/Model/Sortable/Sortable.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public function getSort()
* Set sort.
*
* @param int $sort Sort the value to set
*
* @return $this
*/
public function setSort($sort)
{
Expand All @@ -49,9 +47,6 @@ public function isReordered()
return $this->reordered;
}

/**
* @return $this
*/
public function setReordered()
{
$this->reordered = true;
Expand Down
21 changes: 9 additions & 12 deletions src/Model/Timestampable/TimestampableMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

namespace Knp\DoctrineBehaviors\Model\Timestampable;

use DateTime;
use DateTimeZone;

trait TimestampableMethods
{
/**
* Returns createdAt value.
*
* @return \DateTime
* @return DateTime
*/
public function getCreatedAt()
{
Expand All @@ -19,27 +22,21 @@ public function getCreatedAt()
/**
* Returns updatedAt value.
*
* @return \DateTime
* @return DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}

/**
* @return $this
*/
public function setCreatedAt(\DateTime $createdAt)
public function setCreatedAt(DateTime $createdAt)
{
$this->createdAt = $createdAt;

return $this;
}

/**
* @return $this
*/
public function setUpdatedAt(\DateTime $updatedAt)
public function setUpdatedAt(DateTime $updatedAt)
{
$this->updatedAt = $updatedAt;

Expand All @@ -52,8 +49,8 @@ public function setUpdatedAt(\DateTime $updatedAt)
public function updateTimestamps(): void
{
// Create a datetime with microseconds
$dateTime = \DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)));
$dateTime->setTimezone(new \DateTimeZone(date_default_timezone_get()));
$dateTime = DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)));
$dateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));

if ($this->createdAt === null) {
$this->createdAt = $dateTime;
Expand Down
Loading

0 comments on commit 2d22250

Please sign in to comment.