Skip to content

Commit 246d131

Browse files
committed
Code: apply codesniffer
1 parent e38fc8f commit 246d131

45 files changed

Lines changed: 254 additions & 322 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎ruleset.xml‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<ruleset name="Contributte" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
33
<!-- Rulesets -->
4-
<rule ref="./vendor/contributte/qa/ruleset-8.0.xml"/>
4+
<rule ref="./vendor/contributte/qa/ruleset-8.0.xml">
5+
<exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming.SuperfluousSuffix"/>
6+
<exclude name="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming.SuperfluousSuffix"/>
7+
<exclude name="SlevomatCodingStandard.PHP.DisallowReference.DisallowedReturningReference"/>
8+
</rule>
59

610
<!-- Rules -->
711
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
812
<properties>
913
<property name="rootNamespaces" type="array">
1014
<element key="src" value="Contributte\Imagist"/>
11-
<element key="tests" value="Tests"/>
15+
<element key="tests/src" value="Tests\Testing"/>
16+
<element key="tests/unit" value="Tests\Unit"/>
17+
<element key="tests/functional" value="Tests\Functional"/>
18+
<element key="tests/_support/Helper" value="Tests\Helper"/>
19+
<element key="tests/_support" value="Tests"/>
1220
</property>
1321
<property name="extensions" type="array">
1422
<element key="php" value="php"/>
@@ -18,5 +26,5 @@
1826
</rule>
1927

2028
<!-- Excludes -->
21-
<exclude-pattern>/tests/tmp</exclude-pattern>
29+
<exclude-pattern>/tests</exclude-pattern>
2230
</ruleset>

‎src/Bridge/Doctrine/ImageType.php‎

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,40 @@ class ImageType extends StringType
2323

2424
private string $name = 'image';
2525

26+
/**
27+
* @param class-string<PersistentImage> $className
28+
*/
29+
public static function register(Connection $connection, string $name = 'image', string $dbName = 'db_image', string $className = PersistentImage::class): void
30+
{
31+
if (!$connection->getDatabasePlatform()->hasDoctrineTypeMappingFor($dbName)) {
32+
self::registerType($name, $className);
33+
34+
$connection->getDatabasePlatform()->registerDoctrineTypeMapping($dbName, $name);
35+
}
36+
}
37+
38+
/**
39+
* @param class-string<PersistentImage> $className
40+
*/
41+
public static function registerType(string $name = 'image', string $className = PersistentImage::class): void
42+
{
43+
if (Type::hasType($name)) {
44+
$class = Type::getTypesMap()[$name];
45+
46+
if ($class !== static::class) {
47+
throw new LogicException(
48+
sprintf('Doctrine type %s is already registered for class %s', $name, $class)
49+
);
50+
}
51+
} else {
52+
$self = new self();
53+
$self->name = $name;
54+
$self->className = $className;
55+
56+
self::getTypeRegistry()->register($name, $self);
57+
}
58+
}
59+
2660
public function getDatabaseConverter(): DatabaseConverterInterface
2761
{
2862
if (!isset($this->databaseConverter)) {
@@ -81,38 +115,4 @@ public function requiresSQLCommentHint(AbstractPlatform $platform): bool
81115
return true;
82116
}
83117

84-
/**
85-
* @param class-string<PersistentImage> $className
86-
*/
87-
public static function register(Connection $connection, string $name = 'image', string $dbName = 'db_image', string $className = PersistentImage::class): void
88-
{
89-
if (!$connection->getDatabasePlatform()->hasDoctrineTypeMappingFor($dbName)) {
90-
self::registerType($name, $className);
91-
92-
$connection->getDatabasePlatform()->registerDoctrineTypeMapping($dbName, $name);
93-
}
94-
}
95-
96-
/**
97-
* @param class-string<PersistentImage> $className
98-
*/
99-
public static function registerType(string $name = 'image', string $className = PersistentImage::class): void
100-
{
101-
if (Type::hasType($name)) {
102-
$class = Type::getTypesMap()[$name];
103-
104-
if ($class !== static::class) {
105-
throw new LogicException(
106-
sprintf('Doctrine type %s is already registered for class %s', $name, $class)
107-
);
108-
}
109-
} else {
110-
$self = new self();
111-
$self->name = $name;
112-
$self->className = $className;
113-
114-
self::getTypeRegistry()->register($name, $self);
115-
}
116-
}
117-
118118
}

‎src/Bridge/Gumlet/GumletBuilder.php‎

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,12 @@ class GumletBuilder
1010
/** @var mixed[] */
1111
private array $options = [];
1212

13-
/**
14-
* @return self
15-
*/
16-
public static function create()
13+
public static function create(): self
1714
{
1815
return new self();
1916
}
2017

21-
/**
22-
* @param int|string|null $width
23-
* @param int|string|null $height
24-
* @return self
25-
*/
26-
public function resize($width = null, $height = null, ?string $mode = null)
18+
public function resize(int|string|null $width = null, int|string|null $height = null, ?string $mode = null): self
2719
{
2820
if (($width ?? $height) === null) {
2921
throw new InvalidArgumentException('Height or width must be set');
@@ -44,43 +36,28 @@ public function resize($width = null, $height = null, ?string $mode = null)
4436
return $this;
4537
}
4638

47-
/**
48-
* @return self
49-
*/
50-
public function crop(string $mode)
39+
public function crop(string $mode): self
5140
{
5241
$this->options['crop'] = $mode;
5342

5443
return $this;
5544
}
5645

57-
/**
58-
* @return self
59-
*/
60-
public function fill(string $fill)
46+
public function fill(string $fill): self
6147
{
6248
$this->options['fill'] = $fill;
6349

6450
return $this;
6551
}
6652

67-
/**
68-
* @return self
69-
*/
70-
public function mask(string $mask)
53+
public function mask(string $mask): self
7154
{
7255
$this->options['mask'] = $mask;
7356

7457
return $this;
7558
}
7659

77-
/**
78-
* @param int|string $left
79-
* @param int|string $top
80-
* @param int|string $width
81-
* @param int|string $height
82-
*/
83-
public function extract($left, $top, $width, $height): self
60+
public function extract(int|string $left, int|string $top, int|string $width, int|string $height): self
8461
{
8562
$this->options['extract'] = implode(',', [$left, $top, $width, $height]);
8663

‎src/Bridge/Gumlet/GumletOperationProcessor.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function process(object $resource, OperationCollection $collection, Conte
4646
if ($crop = $collection->get(CropOperation::class)) {
4747
$builder->extract($crop->getLeft(), $crop->getTop(), $crop->getWidth(), $crop->getHeight());
4848
}
49-
49+
5050
if ($fill = $collection->get(GumletFillOperation::class)) {
5151
$builder->fill($fill->getFill());
5252
}

‎src/Bridge/Imagine/ImagineResourceFactory.php‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ public function __construct()
2222
$this->imagine = $this->createImagine();
2323
}
2424

25+
public function create(FileInterface $source, ContextInterface $context): ImageInterface
26+
{
27+
return $this->imagine->load($source->getContent());
28+
}
29+
30+
public function toString(object $resource, FileInterface $source, ContextInterface $context): string
31+
{
32+
assert($resource instanceof ImageInterface);
33+
34+
return $resource->get($source->getMimeType()->toSuffix());
35+
}
36+
2537
protected function createImagine(): ImagineInterface
2638
{
2739
if (extension_loaded('imagick')) {
@@ -39,16 +51,4 @@ protected function createImagine(): ImagineInterface
3951
throw new RuntimeException('PHP extension not found, need imagick or gd or gmagick');
4052
}
4153

42-
public function create(FileInterface $source, ContextInterface $context): ImageInterface
43-
{
44-
return $this->imagine->load($source->getContent());
45-
}
46-
47-
public function toString(object $resource, FileInterface $source, ContextInterface $context): string
48-
{
49-
assert($resource instanceof ImageInterface);
50-
51-
return $resource->get($source->getMimeType()->toSuffix());
52-
}
53-
5454
}

‎src/Bridge/Nette/DI/ImagistExtension.php‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,20 @@ public function loadConfiguration(): void
168168
$this->loadTracy($builder);
169169
}
170170

171+
public function beforeCompile(): void
172+
{
173+
$builder = $this->getContainerBuilder();
174+
175+
Arrays::invoke($this->onBeforeCompile);
176+
177+
try {
178+
$this->assertServiceDefinition($builder->getDefinitionByType(BlueScreen::class))
179+
->addSetup('?::install(?);', [ImagistBlueScreen::class, '@self']);
180+
} catch (MissingServiceException $e) {
181+
// no need
182+
}
183+
}
184+
171185
private function loadTracy(ContainerBuilder $builder): void
172186
{
173187
/** @var stdClass $config */
@@ -198,20 +212,6 @@ private function loadTracy(ContainerBuilder $builder): void
198212
};
199213
}
200214

201-
public function beforeCompile(): void
202-
{
203-
$builder = $this->getContainerBuilder();
204-
205-
Arrays::invoke($this->onBeforeCompile);
206-
207-
try {
208-
$this->assertServiceDefinition($builder->getDefinitionByType(BlueScreen::class))
209-
->addSetup('?::install(?);', [ImagistBlueScreen::class, '@self']);
210-
} catch (MissingServiceException $e) {
211-
// no need
212-
}
213-
}
214-
215215
private function loadFilesystem(ContainerBuilder $builder): void
216216
{
217217
/** @var stdClass $config */

‎src/Bridge/Nette/DI/ImagistNeonFiltersExtension.php‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function getConfigSchema(): Schema
2727
]);
2828
}
2929

30-
public function loadConfiguration()
30+
public function loadConfiguration(): void
3131
{
3232
$builder = $this->getContainerBuilder();
3333

@@ -36,7 +36,7 @@ public function loadConfiguration()
3636
->setFactory(StringFilterCollection::class);
3737
}
3838

39-
public function beforeCompile()
39+
public function beforeCompile(): void
4040
{
4141
/** @var stdClass $config */
4242
$config = $this->getConfig();
@@ -67,11 +67,7 @@ private function processFilters(array $statements, array $aliases): array
6767
$return = [];
6868

6969
foreach ($statements as $name => $statement) {
70-
if (is_string($statement)) {
71-
$statement = new Statement($statement);
72-
} else {
73-
$statement = $this->processStatement($statement, $aliases);
74-
}
70+
$statement = is_string($statement) ? new Statement($statement) : $this->processStatement($statement, $aliases);
7571

7672
if (!is_string($name)) {
7773
$name = null;
@@ -86,9 +82,7 @@ private function processFilters(array $statements, array $aliases): array
8682
}
8783

8884
/**
89-
* @param Statement $statement
9085
* @param array<string, string> $aliases
91-
* @return Statement
9286
*/
9387
private function processStatement(Statement $statement, array $aliases): Statement
9488
{

‎src/Bridge/Nette/Form/ImageUploadControl.php‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,17 @@ public function loadHttpData(): void
5858
/**
5959
* @return static
6060
*/
61-
public function setScope(?Scope $scope)
61+
public function setScope(?Scope $scope): static
6262
{
6363
$this->scope = $scope;
6464

6565
return $this;
6666
}
6767

6868
/**
69-
* @param FileUpload|PersistentImageInterface|string|null $value
7069
* @return static
7170
*/
72-
public function setValue($value)
71+
public function setValue(FileUpload|PersistentImageInterface|string|null $value): static
7372
{
7473
if ($value === null) {
7574
$this->entity = $this->entity->withValue();
@@ -96,7 +95,7 @@ public function setValue($value)
9695
->withValue(null);
9796
} else {
9897
// @phpstan-ignore-next-line $value is mixed
99-
$type = is_object($value) ? get_class($value) : gettype($value);
98+
$type = is_object($value) ? $value::class : gettype($value);
10099

101100
throw new InvalidArgumentException(
102101
sprintf('Value must be %s|%s|string|null, %s given', FileUpload::class, PersistentImageInterface::class, $type)
@@ -183,7 +182,7 @@ public function getControl(): Html
183182
/**
184183
* @return static
185184
*/
186-
public function setPreview(?ImagePreviewInterface $preview)
185+
public function setPreview(?ImagePreviewInterface $preview): static
187186
{
188187
$this->preview = $preview;
189188

@@ -193,7 +192,7 @@ public function setPreview(?ImagePreviewInterface $preview)
193192
/**
194193
* @return static
195194
*/
196-
public function setRemove(?ImageRemoveInterface $remove)
195+
public function setRemove(?ImageRemoveInterface $remove): static
197196
{
198197
$this->remove = $remove;
199198

‎src/Bridge/Nette/Form/Preview/ImagePreview.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function getWrapperPart(): Html
4444
/**
4545
* @return static
4646
*/
47-
public function setFilter(FilterInterface $filter)
47+
public function setFilter(FilterInterface $filter): static
4848
{
4949
$this->filter = $filter;
5050

@@ -54,7 +54,7 @@ public function setFilter(FilterInterface $filter)
5454
/**
5555
* @return static
5656
*/
57-
public function setPlaceholderLink(?string $link)
57+
public function setPlaceholderLink(?string $link): static
5858
{
5959
if ($this->placeholder) {
6060
throw new LogicException('Cannot set placeholder with placeholder link');
@@ -68,7 +68,7 @@ public function setPlaceholderLink(?string $link)
6868
/**
6969
* @return static
7070
*/
71-
public function setPlaceholder(?PersistentImageInterface $placeholder)
71+
public function setPlaceholder(?PersistentImageInterface $placeholder): static
7272
{
7373
if ($this->placeholderLink) {
7474
throw new LogicException('Cannot set placeholder with placeholder link');

0 commit comments

Comments
 (0)