Skip to content

Commit

Permalink
[cs] rector add nette-utils-code-quality
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Dec 12, 2019
1 parent c2a14b8 commit a242a54
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
3 changes: 1 addition & 2 deletions rector-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ parameters:
- 'dead-code'
- 'code-quality'
- 'coding-style'
# - 'nette-utils-code-quality'
# - 'type-declaration'
- 'nette-utils-code-quality'

exclude_rectors:
- 'Rector\DeadCode\Rector\Class_\RemoveUnusedDoctrineEntityMethodAndPropertyRector'
Expand Down
8 changes: 6 additions & 2 deletions src/Model/Sluggable/SluggableMethodsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Knp\DoctrineBehaviors\Model\Sluggable;

use Behat\Transliterator\Transliterator;
use Nette\Utils\Strings;
use UnexpectedValueException;

trait SluggableMethodsTrait
Expand Down Expand Up @@ -71,10 +72,13 @@ private function generateSlugValue($values)
$sluggableText = Transliterator::transliterate($sluggableText, $this->getSlugDelimiter());

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

return preg_replace('#[\\/_|+ -]+#', $this->getSlugDelimiter(), $urlized);
return Strings::replace($urlized, '#[\\/_|+ -]+#', $this->getSlugDelimiter());
}

private function ensureAtLeastOneUsableValue(array $values, array $usableValues): void
Expand Down
3 changes: 2 additions & 1 deletion src/Model/Translatable/TranslationMethodsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
namespace Knp\DoctrineBehaviors\Model\Translatable;

use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
use Nette\Utils\Strings;

trait TranslationMethodsTrait
{
public static function getTranslatableEntityClass(): string
{
// By default, the translatable class has the same name but without the "Translation" suffix
return substr(self::class, 0, -11);
return Strings::substring(self::class, 0, -11);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/ORM/Joinable/JoinableRepositoryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Knp\DoctrineBehaviors\ORM\Joinable;

use Doctrine\ORM\QueryBuilder;
use Nette\Utils\Strings;

trait JoinableRepositoryTrait
{
Expand Down Expand Up @@ -50,7 +51,7 @@ private function addJoinsToQueryBuilder($alias, QueryBuilder $queryBuilder, $cla
private function getAlias($className)
{
$shortName = $this->getEntityManager()->getClassMetadata($className)->reflClass->getShortName();
return strtolower(substr($shortName, 0, 1));
return strtolower(Strings::substring($shortName, 0, 1));
}

private function getUniqueAlias($className, QueryBuilder $queryBuilder)
Expand Down
3 changes: 2 additions & 1 deletion tests/ORM/Tree/NodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Knp\DoctrineBehaviors\Tests\Fixtures\ORM\TreeNodeEntity;
use Knp\DoctrineBehaviors\Tests\Fixtures\ORM\TreeNodeEntityRepository;
use LogicException;
use Nette\Utils\Json;

final class NodeTest extends AbstractBehaviorTestCase
{
Expand Down Expand Up @@ -164,7 +165,7 @@ public function testToJson(): void
{
$expected = $this->provideToArray();
$tree = $this->buildTree();
$this->assertSame(json_encode($expected), $tree->toJson());
$this->assertSame(Json::encode($expected), $tree->toJson());
}

public function testToFlatArray(): void
Expand Down

0 comments on commit a242a54

Please sign in to comment.