Skip to content

Commit 7125d6e

Browse files
authored
Create Pipeline (#7)
Setup pipeline with tests and cs-fixer
1 parent fc9253b commit 7125d6e

24 files changed

Lines changed: 177 additions & 121 deletions

.github/workflows/tests.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Tests
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
tests:
11+
name: "PHP ${{ matrix.php-version }}"
12+
runs-on: ubuntu-latest
13+
continue-on-error: false
14+
strategy:
15+
matrix:
16+
php-version: ['8.2', '8.3']
17+
steps:
18+
- name: Setup PHP
19+
uses: shivammathur/setup-php@v2
20+
with:
21+
php-version: ${{ matrix.php-version }}
22+
tools: composer:v2
23+
- name: Checkout code
24+
uses: actions/checkout@v3
25+
- name: Install Dependencies
26+
run: composer update --no-interaction --prefer-dist --optimize-autoloader --prefer-stable
27+
- name: PHP-CS-Fixer
28+
run: vendor/bin/php-cs-fixer fix --diff --dry-run
29+
- name: Run tests
30+
run: vendor/bin/phpunit
31+
32+

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/vendor/
33
.phpunit.cache
44
composer.lock
5+
.php-cs-fixer.cache

.php-cs-fixer.dist.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->in(__DIR__)
5+
->exclude('var');
6+
7+
$config = new PhpCsFixer\Config();
8+
return $config
9+
->setRiskyAllowed(true)
10+
->setRules([
11+
'@Symfony' => true,
12+
'@Symfony:risky' => true,
13+
'array_syntax' => ['syntax' => 'short'],
14+
'yoda_style' => false,
15+
])
16+
->setFinder($finder);

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"require-dev": {
2424
"phpunit/phpunit": "^10.5",
2525
"symfony/browser-kit": "^6.4|^7.0",
26-
"symfony/css-selector": "^6.4|^7.0"
26+
"symfony/css-selector": "^6.4|^7.0",
27+
"friendsofphp/php-cs-fixer": "^3.51"
2728
}
2829
}

config/documentation.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
@@ -10,7 +11,7 @@
1011
use Qossmic\TwigDocBundle\Twig\TwigDocExtension;
1112

1213
return static function (ContainerConfigurator $container) {
13-
$container->services() ->set('twig_doc.controller.documentation', TwigDocController::class)
14+
$container->services()->set('twig_doc.controller.documentation', TwigDocController::class)
1415
->public()
1516
->autoconfigure()
1617
->autowire()
@@ -35,5 +36,5 @@
3536
->autowire()
3637
->tag('twig.extension')
3738
->alias(TwigDocExtension::class, 'twig_doc.twig.extension')
38-
;
39+
;
3940
};

src/Component/ComponentCategory.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace Qossmic\TwigDocBundle\Component;
@@ -15,14 +16,15 @@ class ComponentCategory
1516
#[Assert\Regex('/^\w+$/')]
1617
private string $name;
1718

18-
public function getParent(): ?ComponentCategory
19+
public function getParent(): ?self
1920
{
2021
return $this->parent;
2122
}
2223

23-
public function setParent(?ComponentCategory $parent): ComponentCategory
24+
public function setParent(?self $parent): self
2425
{
2526
$this->parent = $parent;
27+
2628
return $this;
2729
}
2830

@@ -31,9 +33,10 @@ public function getName(): string
3133
return $this->name;
3234
}
3335

34-
public function setName(string $name): ComponentCategory
36+
public function setName(string $name): self
3537
{
3638
$this->name = $name;
39+
3740
return $this;
3841
}
3942
}

src/Component/ComponentInvalid.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace Qossmic\TwigDocBundle\Component;

src/Component/ComponentItem.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace Qossmic\TwigDocBundle\Component;
@@ -30,9 +31,10 @@ public function getName(): string
3031
return $this->name;
3132
}
3233

33-
public function setName(string $name): ComponentItem
34+
public function setName(string $name): self
3435
{
3536
$this->name = $name;
37+
3638
return $this;
3739
}
3840

@@ -41,9 +43,10 @@ public function getTitle(): string
4143
return $this->title;
4244
}
4345

44-
public function setTitle(string $title): ComponentItem
46+
public function setTitle(string $title): self
4547
{
4648
$this->title = $title;
49+
4750
return $this;
4851
}
4952

@@ -52,9 +55,10 @@ public function getDescription(): string
5255
return $this->description;
5356
}
5457

55-
public function setDescription(string $description): ComponentItem
58+
public function setDescription(string $description): self
5659
{
5760
$this->description = $description;
61+
5862
return $this;
5963
}
6064

@@ -63,9 +67,10 @@ public function getTags(): array
6367
return $this->tags;
6468
}
6569

66-
public function setTags(array $tags): ComponentItem
70+
public function setTags(array $tags): self
6771
{
6872
$this->tags = $tags;
73+
6974
return $this;
7075
}
7176

@@ -74,27 +79,28 @@ public function getParameters(): array
7479
return $this->parameters;
7580
}
7681

77-
public function setParameters(array $parameters): ComponentItem
82+
public function setParameters(array $parameters): self
7883
{
7984
$this->parameters = $parameters;
8085

8186
return $this;
8287
}
8388

84-
public function setVariations(array $variations): ComponentItem
89+
public function setVariations(array $variations): self
8590
{
8691
$this->variations = $variations;
8792

8893
return $this;
8994
}
9095

91-
public function addParameter(string $name, mixed $value): ComponentItem
96+
public function addParameter(string $name, mixed $value): self
9297
{
9398
$this->parameters[$name] = $value;
99+
94100
return $this;
95101
}
96102

97-
public function removeParameter(string $name): ComponentItem
103+
public function removeParameter(string $name): self
98104
{
99105
unset($this->parameters[$name]);
100106

@@ -106,13 +112,14 @@ public function getVariations(): array
106112
return $this->variations;
107113
}
108114

109-
public function addVariation(string $name, array $variation): ComponentItem
115+
public function addVariation(string $name, array $variation): self
110116
{
111117
$this->variations[$name] = $variation;
118+
112119
return $this;
113120
}
114121

115-
public function removeVariation(string $name): ComponentItem
122+
public function removeVariation(string $name): self
116123
{
117124
unset($this->variations[$name]);
118125

@@ -124,9 +131,10 @@ public function getCategory(): ComponentCategory
124131
return $this->category;
125132
}
126133

127-
public function setCategory(ComponentCategory $category): ComponentItem
134+
public function setCategory(ComponentCategory $category): self
128135
{
129136
$this->category = $category;
137+
130138
return $this;
131139
}
132140

src/Component/ComponentItemFactory.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace Qossmic\TwigDocBundle\Component;
56

6-
use Symfony\Component\Validator\ConstraintViolationList;
7-
use Symfony\Component\Validator\Validator\ValidatorInterface;
87
use Qossmic\TwigDocBundle\Exception\InvalidComponentConfigurationException;
98
use Qossmic\TwigDocBundle\Service\CategoryService;
9+
use Symfony\Component\Validator\ConstraintViolationList;
10+
use Symfony\Component\Validator\Validator\ValidatorInterface;
1011

1112
class ComponentItemFactory
1213
{
@@ -23,7 +24,7 @@ public function create(array $data): ComponentItem
2324
if ($category === null) {
2425
$violations = ConstraintViolationList::createFromMessage(
2526
sprintf(
26-
"invalid %s \"%s\". Valid categories are: %s. Valid sub-categories are: %s",
27+
'invalid %s "%s". Valid categories are: %s. Valid sub-categories are: %s',
2728
isset($data['sub_category']) ? 'sub_category' : 'category',
2829
$data['sub_category'] ?? $data['category'],
2930
implode(', ', array_keys($this->categoryService->getCategories())),
@@ -53,7 +54,7 @@ private function createItem(array $data): ComponentItem
5354
->setTags($data['tags'] ?? [])
5455
->setParameters($data['parameters'] ?? [])
5556
->setVariations($data['variations'] ?? [
56-
'default' => $this->createVariationParameters($data['parameters'] ?? [])
57+
'default' => $this->createVariationParameters($data['parameters'] ?? []),
5758
]);
5859

5960
return $item;
@@ -63,7 +64,7 @@ public function createVariationParameters(array $parameters): array
6364
{
6465
$params = [];
6566
foreach ($parameters as $name => $type) {
66-
if (is_array($type)) {
67+
if (\is_array($type)) {
6768
$paramValue = $this->createVariationParameters($type);
6869
} else {
6970
$paramValue = $this->createParamValue($type);
@@ -86,7 +87,7 @@ private function createParamValue(string $type): bool|int|float|string|null
8687
return random_int(0, 100000);
8788
case 'bool':
8889
case 'boolean':
89-
return [true, false][rand(0,1)];
90+
return [true, false][rand(0, 1)];
9091
case 'float':
9192
case 'double':
9293
return (float) rand(1, 1000) / 100;

src/Controller/TwigDocController.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace Qossmic\TwigDocBundle\Controller;
56

7+
use Qossmic\TwigDocBundle\Service\ComponentService;
68
use Symfony\Component\HttpFoundation\Request;
79
use Symfony\Component\HttpFoundation\Response;
810
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
911
use Symfony\Component\HttpKernel\Profiler\Profiler;
1012
use Twig\Environment;
11-
use Qossmic\TwigDocBundle\Component\ComponentItem;
12-
use Qossmic\TwigDocBundle\Service\ComponentService;
1313

1414
class TwigDocController
1515
{
1616
public function __construct(
1717
private readonly Environment $twig,
1818
private readonly ComponentService $componentService,
1919
private readonly ?Profiler $profiler = null
20-
)
21-
{
20+
) {
2221
}
2322

2423
public function index(Request $request): Response
@@ -55,14 +54,15 @@ public function componentView(Request $request): Response
5554
}
5655
$breakpoint = $request->query->get('breakpoint');
5756
// disable profiler to get rid of toolbar in dev
58-
if($this->profiler) {
59-
$this->profiler->disable();
57+
if ($this->profiler) {
58+
$this->profiler->disable();
6059
}
60+
6161
return new Response(
6262
$this->twig->render('@TwigDoc/component.html.twig', [
6363
'component' => $component,
6464
'componentData' => $request->query->all('data'),
65-
'quantity' => $request->query->get('quantity')
65+
'quantity' => $request->query->get('quantity'),
6666
])
6767
);
6868
}

0 commit comments

Comments
 (0)