Skip to content

Commit

Permalink
#11 code review changes
Browse files Browse the repository at this point in the history
- added cs-fixer rule for strict types
  • Loading branch information
davidhoelzel committed Apr 4, 2024
1 parent 5c1aa72 commit 4351e75
Show file tree
Hide file tree
Showing 24 changed files with 54 additions and 12 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHP80Migration:risky' => true,
'array_syntax' => ['syntax' => 'short'],
'yoda_style' => false,
])
Expand Down
11 changes: 9 additions & 2 deletions config/documentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,30 @@
use Qossmic\TwigDocBundle\Service\ComponentService;
use Qossmic\TwigDocBundle\Twig\TwigDocExtension;

return static function (ContainerConfigurator $container) {
$container->services()->set('twig_doc.controller.documentation', TwigDocController::class)
return static function (ContainerConfigurator $container): void {
$container->services()
->set('twig_doc.controller.documentation', TwigDocController::class)
->public()
->arg('$twig', service('twig'))
->arg('$componentService', service('twig_doc.service.component'))
->arg('$profiler', service('profiler')->nullOnInvalid())

->set('twig_doc.service.category', CategoryService::class)
->alias(CategoryService::class, 'twig_doc.service.category')

->set('twig_doc.service.component_factory', ComponentItemFactory::class)
->public()
->arg('$validator', service('validator'))
->arg('$categoryService', service('twig_doc.service.category'))
->arg('$faker', service('twig_doc.service.faker'))
->alias(ComponentItemFactory::class, 'twig_doc.service.component_factory')

->set('twig_doc.service.component', ComponentService::class)
->public()
->arg('$itemFactory', service('twig_doc.service.component_factory'))
->arg('$cache', service('cache.app'))
->alias(ComponentService::class, 'twig_doc.service.component')

->set('twig_doc.twig.extension', TwigDocExtension::class)
->public()
->arg('$componentRenderer', service('ux.twig_component.component_renderer')->nullOnInvalid())
Expand All @@ -42,6 +47,7 @@
->arg('$twig', service('twig'))
->tag('twig.extension')
->alias(TwigDocExtension::class, 'twig_doc.twig.extension')

->set('twig_doc.cache_warmer', ComponentsWarmer::class)
->arg('$container', service('service_container'))
->tag('kernel.cache_warmer')
Expand All @@ -54,6 +60,7 @@
->set('twig_doc.data_generator.scalar', ScalarGenerator::class)
->public()
->tag('twig_doc.data_generator', ['priority' => -5])

->set('twig_doc.data_generator.fixture', FixtureGenerator::class)
->public()
->tag('twig_doc.data_generator', ['priority' => -10])
Expand Down
4 changes: 1 addition & 3 deletions src/Component/ComponentItemList.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ static function (ComponentItem $item) use ($query) {
break;
case 'tags':
$tags = array_map('trim', explode(',', strtolower($query)));
$components = array_filter($this->getArrayCopy(), static function (ComponentItem $item) use ($tags) {
return array_intersect($tags, array_map('strtolower', $item->getTags())) !== [];
});
$components = array_filter($this->getArrayCopy(), static fn (ComponentItem $item) => array_intersect($tags, array_map('strtolower', $item->getTags())) !== []);

break;
case 'name':
Expand Down
2 changes: 2 additions & 0 deletions src/Component/Data/Faker.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Qossmic\TwigDocBundle\Component\Data;

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Component/Data/FixtureData.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Qossmic\TwigDocBundle\Component\Data;

use Symfony\Component\PropertyInfo\Type;
Expand Down
2 changes: 2 additions & 0 deletions src/Component/Data/Generator/FixtureGenerator.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Qossmic\TwigDocBundle\Component\Data\Generator;

use Nelmio\Alice\Loader\NativeLoader;
Expand Down
2 changes: 2 additions & 0 deletions src/Component/Data/Generator/NullGenerator.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Qossmic\TwigDocBundle\Component\Data\Generator;

use Qossmic\TwigDocBundle\Component\Data\GeneratorInterface;
Expand Down
4 changes: 3 additions & 1 deletion src/Component/Data/Generator/ScalarGenerator.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Qossmic\TwigDocBundle\Component\Data\Generator;

use Faker\Factory;
Expand Down Expand Up @@ -48,7 +50,7 @@ public function createParamValue(string $type): bool|int|float|string|null
return $this->generator->numberBetween(0, 100000);
case 'bool':
case 'boolean':
return [true, false][rand(0, 1)];
return [true, false][random_int(0, 1)];
case 'float':
case 'double':
return $this->generator->randomFloat();
Expand Down
2 changes: 2 additions & 0 deletions src/Component/Data/GeneratorInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Qossmic\TwigDocBundle\Component\Data;

interface GeneratorInterface
Expand Down
4 changes: 1 addition & 3 deletions src/Service/ComponentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ public function filter(string $filterQuery, string $filterType): ComponentItemLi
{
$hash = sprintf('twig_doc_bundle.search.%s.%s', md5($filterQuery.$filterType), $this->configReadTime);

return $this->cache->get($hash, function () use ($filterQuery, $filterType) {
return $this->getComponents()->filter($filterQuery, $filterType);
});
return $this->cache->get($hash, fn () => $this->getComponents()->filter($filterQuery, $filterType));
}

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/TestApp/Component/Data/Generator/CustomGenerator.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Qossmic\TwigDocBundle\Tests\TestApp\Component\Data\Generator;

use Qossmic\TwigDocBundle\Component\Data\GeneratorInterface;
Expand Down
2 changes: 2 additions & 0 deletions tests/TestApp/Entity/Car.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Qossmic\TwigDocBundle\Tests\TestApp\Entity;

class Car
Expand Down
2 changes: 2 additions & 0 deletions tests/TestApp/Entity/Manufacturer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Qossmic\TwigDocBundle\Tests\TestApp\Entity;

class Manufacturer
Expand Down
2 changes: 2 additions & 0 deletions tests/TestApp/Entity/Special.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Qossmic\TwigDocBundle\Tests\TestApp\Entity;

class Special
Expand Down
2 changes: 2 additions & 0 deletions tests/TestApp/config/packages/framework.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

$configuration = [
'secret' => 'F00',
'session' => [
Expand Down
2 changes: 2 additions & 0 deletions tests/TestApp/config/packages/twig.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

$container->loadFromExtension('twig', [
'default_path' => '%kernel.project_dir%/tests/TestApp/templates',
]);
2 changes: 2 additions & 0 deletions tests/TestApp/config/packages/twig_doc.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

$config = [
'directories' => [
'%twig.default_path%/snippets',
Expand Down
4 changes: 3 additions & 1 deletion tests/TestApp/config/services.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

declare(strict_types=1);

use Psr\Log\NullLogger;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $container) {
return static function (ContainerConfigurator $container): void {
$container->services()
->defaults()
->autowire()
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Component/ComponentItemFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testValidComponent(array $componentData): void
static::assertInstanceOf(ComponentCategory::class, $item->getCategory());
}

public function testInvalidCategory()
public function testInvalidCategory(): void
{
$this->expectException(InvalidComponentConfigurationException::class);

Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Component/Data/FakerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Qossmic\TwigDocBundle\Tests\Unit\Component\Data;

use PHPUnit\Framework\Attributes\CoversClass;
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Component/Data/Generator/FixtureGeneratorTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Qossmic\TwigDocBundle\Tests\Unit\Component\Data\Generator;

use PHPUnit\Framework\Attributes\CoversClass;
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Component/Data/Generator/NullGeneratorTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Qossmic\TwigDocBundle\Tests\Unit\Component\Data\Generator;

use PHPUnit\Framework\Attributes\CoversClass;
Expand Down
4 changes: 3 additions & 1 deletion tests/Unit/Component/Data/Generator/ScalarGeneratorTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Qossmic\TwigDocBundle\Tests\Unit\Component\Data\Generator;

use PHPUnit\Framework\Attributes\CoversClass;
Expand All @@ -13,7 +15,7 @@
class ScalarGeneratorTest extends TestCase
{
#[DataProvider('getSupportsTestCases')]
public function testSupports(string $type, mixed $context, bool $expected)
public function testSupports(string $type, mixed $context, bool $expected): void
{
$generator = new ScalarGenerator();

Expand Down
2 changes: 2 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use Qossmic\TwigDocBundle\Tests\TestApp\Kernel;
use Symfony\Component\Filesystem\Filesystem;

Expand Down

0 comments on commit 4351e75

Please sign in to comment.