Skip to content
This repository was archived by the owner on Mar 5, 2022. It is now read-only.

Commit ac4fd60

Browse files
committed
Add code sniffer.
1 parent 9dcf806 commit ac4fd60

24 files changed

+138
-122
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ Contributing
7575
To contribute to this plugin please follow a few basic rules.
7676

7777
* Pull requests must be send to the branch that reflects the version you want to contribute to.
78-
* Contributions must follow the [PSR2-**R** coding standard recommendation](https://github.com/php-fig-rectified/fig-rectified-standards).
7978
* [Unit tests](http://book.cakephp.org/4.0/en/development/testing.html) are required.
8079

8180
License

composer.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"cakephp/plugin-installer": "^1.3.0",
2828
"phauthentic/file-storage-image-processor": "dev-develop",
2929
"phpunit/phpunit": "^8.0",
30+
"spryker/code-sniffer": "^0.15.6",
3031
"vlucas/phpdotenv": "^3.3"
3132
},
3233
"repositories": [
@@ -56,8 +57,8 @@
5657
"@test",
5758
"@stan"
5859
],
59-
"cs-check": "phpcs -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/",
60-
"cs-fix": "phpcbf --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/",
60+
"cs-check": "phpcs -p",
61+
"cs-fix": "phpcbf -p",
6162
"stan": "phpstan analyse src/ && psalm --show-info=false",
6263
"stan-test": "phpstan analyse tests/",
6364
"psalm": "psalm --show-info=false",

phpcs.xml

+8-17
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
<?xml version="1.0"?>
2-
<ruleset name="PSR2-Fuck-Spaces">
3-
<rule ref="vendor/cakephp/cakephp-codesniffer/CakePHP/ruleset.xml"/>
4-
<file>./src</file>
5-
<file>./tests</file>
6-
<rule ref="PSR2">
7-
<exclude name="PSR2.Classes.ClassDeclaration"/>
8-
<exclude name="Generic.WhiteSpace.DisallowTabIndent"/>
9-
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine"/>
10-
</rule>
11-
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>
12-
<rule ref="Generic.WhiteSpace.ScopeIndent">
13-
<properties>
14-
<property name="indent" value="4"/>
15-
<property name="tabIndent" value="true"/>
16-
</properties>
17-
</rule>
18-
<rule ref="Generic.Functions.OpeningFunctionBraceKernighanRitchie"/>
2+
<ruleset name="spryker">
3+
<rule ref="vendor/spryker/code-sniffer/Spryker/ruleset.xml"/>
4+
<file>src/</file>
5+
<file>tests/</file>
6+
7+
<rule ref="PSR2.Classes.PropertyDeclaration">
8+
<severity>0</severity>
9+
</rule>
1910
</ruleset>

src/FileStorage/DataTransformer.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
declare(strict_types=1);
2+
declare(strict_types = 1);
33

44
namespace Burzum\FileStorage\FileStorage;
55

@@ -18,14 +18,14 @@ class DataTransformer implements DataTransformerInterface
1818
/**
1919
* @param \Cake\ORM\Table $table Table
2020
*/
21-
public function __construct(
22-
Table $table
23-
) {
21+
public function __construct(Table $table)
22+
{
2423
$this->table = $table;
2524
}
2625

2726
/**
2827
* @param \Cake\Datasource\EntityInterface $entity
28+
*
2929
* @return \Phauthentic\Infrastructure\Storage\FileInterface
3030
*/
3131
public function entityToFileObject(EntityInterface $entity): FileInterface
@@ -66,6 +66,7 @@ public function entityToFileObject(EntityInterface $entity): FileInterface
6666
/**
6767
* @param \Phauthentic\Infrastructure\Storage\FileInterface $file
6868
* @param \Cake\Datasource\EntityInterface|null $entity
69+
*
6970
* @return \Cake\Datasource\EntityInterface
7071
*/
7172
public function fileObjectToEntity(FileInterface $file, ?EntityInterface $entity): EntityInterface
@@ -80,7 +81,7 @@ public function fileObjectToEntity(FileInterface $file, ?EntityInterface $entity
8081
'variants' => $file->variants(),
8182
'metadata' => $file->metadata(),
8283
'adapter' => $file->storage(),
83-
'path' => $file->path()
84+
'path' => $file->path(),
8485
];
8586

8687
return $entity

src/FileStorage/DataTransformerInterface.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
declare(strict_types=1);
2+
declare(strict_types = 1);
33

44
namespace Burzum\FileStorage\FileStorage;
55

@@ -10,13 +10,15 @@ interface DataTransformerInterface
1010
{
1111
/**
1212
* @param \Cake\Datasource\EntityInterface $entity
13+
*
1314
* @return \Phauthentic\Infrastructure\Storage\FileInterface
1415
*/
1516
public function entityToFileObject(EntityInterface $entity): FileInterface;
1617

1718
/**
1819
* @param \Phauthentic\Infrastructure\Storage\FileInterface $file
1920
* @param \Cake\Datasource\EntityInterface|null $entity
21+
*
2022
* @return \Cake\Datasource\EntityInterface
2123
*/
2224
public function fileObjectToEntity(FileInterface $file, ?EntityInterface $entity): EntityInterface;

src/Model/Behavior/FileStorageBehavior.php

+28-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
declare(strict_types=1);
2+
declare(strict_types = 1);
33

44
namespace Burzum\FileStorage\Model\Behavior;
55

@@ -54,7 +54,7 @@ class FileStorageBehavior extends Behavior
5454
'ignoreEmptyFile' => true,
5555
'fileField' => 'file',
5656
'fileStorage' => null,
57-
'imageProcessor' => null
57+
'imageProcessor' => null,
5858
];
5959

6060
/**
@@ -64,17 +64,19 @@ class FileStorageBehavior extends Behavior
6464

6565
/**
6666
* @inheritDoc
67+
*
68+
* @throws \RuntimeException
6769
*/
6870
public function initialize(array $config): void
6971
{
7072
parent::initialize($config);
7173

72-
if ($this->getConfig('fileStorage') instanceOf FileStorage) {
74+
if ($this->getConfig('fileStorage') instanceof FileStorage) {
7375
$this->fileStorage = $this->getConfig('fileStorage');
7476
} else {
75-
throw new RuntimeException(
77+
throw new RuntimeException(
7678
'Missing or invalid fileStorage config key'
77-
);
79+
);
7880
}
7981

8082
if (!$this->getConfig('dataTransformer') instanceof DataTransformerInterface) {
@@ -85,8 +87,8 @@ public function initialize(array $config): void
8587
}
8688

8789
/**
88-
* @throws \InvalidArgumentException
8990
* @param string $configName
91+
*
9092
* @return \League\Flysystem\AdapterInterface
9193
*/
9294
public function getStorageAdapter(string $configName): AdapterInterface
@@ -98,6 +100,7 @@ public function getStorageAdapter(string $configName): AdapterInterface
98100
* Checks if a file upload is present.
99101
*
100102
* @param \Cake\Datasource\EntityInterface|\ArrayObject $entity
103+
*
101104
* @return bool
102105
*/
103106
protected function isFileUploadPresent($entity)
@@ -125,6 +128,8 @@ protected function isFileUploadPresent($entity)
125128
*
126129
* @param \Cake\Event\EventInterface $event
127130
* @param \ArrayObject $data
131+
* @param \ArrayObject $options
132+
*
128133
* @return void
129134
*/
130135
public function beforeMarshal(EventInterface $event, ArrayObject $data, ArrayObject $options): void
@@ -140,6 +145,7 @@ public function beforeMarshal(EventInterface $event, ArrayObject $data, ArrayObj
140145
* @param \Cake\Event\EventInterface $event
141146
* @param \Cake\Datasource\EntityInterface $entity
142147
* @param \ArrayObject $options
148+
*
143149
* @return void
144150
*/
145151
public function beforeSave(EventInterface $event, EntityInterface $entity, ArrayObject $options): void
@@ -152,7 +158,7 @@ public function beforeSave(EventInterface $event, EntityInterface $entity, Array
152158

153159
$this->dispatchEvent('FileStorage.beforeSave', [
154160
'entity' => $entity,
155-
'storageAdapter' => $this->getStorageAdapter($entity->get('adapter'))
161+
'storageAdapter' => $this->getStorageAdapter($entity->get('adapter')),
156162
], $this->getTable());
157163
}
158164

@@ -162,6 +168,9 @@ public function beforeSave(EventInterface $event, EntityInterface $entity, Array
162168
* @param \Cake\Event\EventInterface $event
163169
* @param \Cake\Datasource\EntityInterface $entity
164170
* @param \ArrayObject $options
171+
*
172+
* @throws \Exception
173+
*
165174
* @return void
166175
*/
167176
public function afterSave(EventInterface $event, EntityInterface $entity, ArrayObject $options): void
@@ -187,20 +196,22 @@ public function afterSave(EventInterface $event, EntityInterface $entity, ArrayO
187196
);
188197
} catch (Throwable $exception) {
189198
$this->getTable()->delete($entity);
199+
190200
throw $exception;
191201
}
192202
}
193203

194204
$this->dispatchEvent('FileStorage.afterSave', [
195205
'entity' => $entity,
196-
'storageAdapter' => $this->getStorageAdapter($entity->get('adapter'))
206+
'storageAdapter' => $this->getStorageAdapter($entity->get('adapter')),
197207
], $this->getTable());
198208
}
199209

200210
/**
201211
* checkEntityBeforeSave
202212
*
203213
* @param \Cake\Datasource\EntityInterface $entity
214+
*
204215
* @return void
205216
*/
206217
protected function checkEntityBeforeSave(EntityInterface $entity)
@@ -222,6 +233,7 @@ protected function checkEntityBeforeSave(EntityInterface $entity)
222233
* @param \Cake\Event\EventInterface $event
223234
* @param \Cake\Datasource\EntityInterface $entity
224235
* @param \ArrayObject $options
236+
*
225237
* @return void
226238
*/
227239
public function afterDelete(EventInterface $event, EntityInterface $entity, ArrayObject $options): void
@@ -243,6 +255,7 @@ public function afterDelete(EventInterface $event, EntityInterface $entity, Arra
243255
*
244256
* @param array|\ArrayAccess $upload
245257
* @param string $field
258+
*
246259
* @return void
247260
*/
248261
protected function getFileInfoFromUpload(&$upload, $field = 'file')
@@ -268,6 +281,7 @@ protected function getFileInfoFromUpload(&$upload, $field = 'file')
268281
* callbacks. So the events that will remove the files won't get fired.
269282
*
270283
* @param array $conditions Query::where() array structure.
284+
*
271285
* @return int Number of deleted records / files
272286
*/
273287
public function deleteAllFiles($conditions)
@@ -290,6 +304,7 @@ public function deleteAllFiles($conditions)
290304

291305
/**
292306
* @param \Cake\Datasource\EntityInterface $entity Entity
307+
*
293308
* @return \Phauthentic\Infrastructure\Storage\FileInterface
294309
*/
295310
public function entityToFileObject(EntityInterface $entity): FileInterface
@@ -300,6 +315,7 @@ public function entityToFileObject(EntityInterface $entity): FileInterface
300315
/**
301316
* @param \Phauthentic\Infrastructure\Storage\FileInterface $file File
302317
* @param \Cake\Datasource\EntityInterface|null $entity
318+
*
303319
* @return \Cake\Datasource\EntityInterface
304320
*/
305321
public function fileObjectToEntity(FileInterface $file, ?EntityInterface $entity)
@@ -312,6 +328,7 @@ public function fileObjectToEntity(FileInterface $file, ?EntityInterface $entity
312328
*
313329
* @param \Phauthentic\Infrastructure\Storage\FileInterface $file File
314330
* @param \Cake\Datasource\EntityInterface $entity
331+
*
315332
* @return \Phauthentic\Infrastructure\Storage\FileInterface
316333
*/
317334
public function processImages(FileInterface $file, EntityInterface $entity): FileInterface
@@ -331,6 +348,8 @@ public function processImages(FileInterface $file, EntityInterface $entity): Fil
331348
}
332349

333350
/**
351+
* @throws \RuntimeException
352+
*
334353
* @return \Phauthentic\Infrastructure\Storage\Processor\ProcessorInterface
335354
*/
336355
protected function getImageProcessor(): ProcessorInterface
@@ -339,7 +358,7 @@ protected function getImageProcessor(): ProcessorInterface
339358
return $this->imageProcessor;
340359
}
341360

342-
if ($this->getConfig('imageProcessor') instanceOf ProcessorInterface) {
361+
if ($this->getConfig('imageProcessor') instanceof ProcessorInterface) {
343362
$this->imageProcessor = $this->getConfig('imageProcessor');
344363
}
345364

src/Model/Entity/FileStorage.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
declare(strict_types=1);
2+
declare(strict_types = 1);
33

44
namespace Burzum\FileStorage\Model\Entity;
55

@@ -27,11 +27,12 @@ class FileStorage extends Entity implements FileStorageEntityInterface
2727
* @var array
2828
*/
2929
protected $_virtual = [
30-
'variantUrls'
30+
'variantUrls',
3131
];
3232

3333
/**
3434
* @param string $variant Variant
35+
*
3536
* @return string|null
3637
*/
3738
public function getVariantUrl(string $variant): ?string
@@ -46,6 +47,7 @@ public function getVariantUrl(string $variant): ?string
4647

4748
/**
4849
* @param string $variant Variant
50+
*
4951
* @return string|null
5052
*/
5153
public function getVariantPath(string $variant): ?string
@@ -63,10 +65,11 @@ public function getVariantPath(string $variant): ?string
6365
*
6466
* @return array
6567
*/
66-
protected function _getVariantUrls() {
68+
protected function _getVariantUrls()
69+
{
6770
$variants = (array)$this->get('variants');
6871
$list = [
69-
'original' => $this->get('url')
72+
'original' => $this->get('url'),
7073
];
7174

7275
foreach ($variants as $name => $data) {

src/Model/Entity/FileStorageEntityInterface.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
declare(strict_types=1);
2+
declare(strict_types = 1);
33

44
namespace Burzum\FileStorage\Model\Entity;
55

@@ -16,12 +16,14 @@ interface FileStorageEntityInterface extends EntityInterface
1616
{
1717
/**
1818
* @param string $variant Variant
19+
*
1920
* @return string|null
2021
*/
2122
public function getVariantUrl(string $variant): ?string;
2223

2324
/**
2425
* @param string $variant Variant
26+
*
2527
* @return string|null
2628
*/
2729
public function getVariantPath(string $variant): ?string;

src/Model/Table/FileStorageTable.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
2-
declare(strict_types=1);
2+
declare(strict_types = 1);
3+
34
namespace Burzum\FileStorage\Model\Table;
45

56
use Cake\Core\Configure;
@@ -41,6 +42,7 @@ public function _initializeSchema(TableSchemaInterface $schema): TableSchemaInte
4142
* Initialize
4243
*
4344
* @param array $config
45+
*
4446
* @return void
4547
*/
4648
public function initialize(array $config): void

src/Plugin.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
declare(strict_types=1);
2+
declare(strict_types = 1);
33

44
namespace Burzum\FileStorage;
55

0 commit comments

Comments
 (0)