Skip to content

Commit 557703b

Browse files
authored
Merge pull request #456 from thephpleague/coding-standard
Coding style
2 parents a1c9e1b + 62b3aeb commit 557703b

58 files changed

Lines changed: 338 additions & 349 deletions

Some content is hidden

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

.github/workflows/test.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
coverage: pcov
2828

2929
- name: Composer install
30-
uses: ramsey/composer-install@v3
30+
uses: ramsey/composer-install@v4
3131
with:
3232
dependency-versions: ${{ matrix.dependencies }}
3333

@@ -41,7 +41,7 @@ jobs:
4141
4242
- name: Code Coverage Report
4343
if: matrix.php-version == '8.3'
44-
uses: codecov/codecov-action@v3
44+
uses: codecov/codecov-action@v7
4545

4646
coding-style:
4747
runs-on: ubuntu-22.04
@@ -54,7 +54,7 @@ jobs:
5454
extensions: gd, imagick
5555

5656
- name: Composer install
57-
uses: ramsey/composer-install@v3
57+
uses: ramsey/composer-install@v4
5858

5959
- name: php-cs-fixer
6060
run: |
@@ -71,7 +71,7 @@ jobs:
7171
extensions: gd, imagick
7272

7373
- name: Composer install
74-
uses: ramsey/composer-install@v3
74+
uses: ramsey/composer-install@v4
7575

7676
- name: phpstan
7777
if: always()

.php-cs-fixer.dist.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
<?php
22

3-
$finder = (new PhpCsFixer\Finder())
3+
declare(strict_types=1);
4+
5+
use PhpCsFixer\Config;
6+
use PhpCsFixer\Finder;
7+
8+
$finder = (new Finder())
49
->in('scripts')
510
->in('src')
6-
->in('tests')
7-
;
11+
->in('tests');
812

9-
return (new PhpCsFixer\Config())
13+
return (new Config())
1014
->setRules([
11-
'@Symfony' => true,
12-
'declare_strict_types' => true,
13-
'phpdoc_annotation_without_dot' => false,
14-
'nullable_type_declaration_for_default_null_value' => [
15-
'use_nullable_type_declaration' => true,
16-
],
17-
'phpdoc_to_comment' => [
18-
'ignored_tags' => ['psalm-suppress', 'phpstan-ignore-line', 'phpstan-ignore-next-line'],
19-
],
15+
'@PER-CS3.0' => true,
16+
'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false],
2017
])
21-
->setFinder($finder)
22-
;
18+
->setFinder($finder);

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ We accept contributions via Pull Requests on [Github](https://github.com/thephpl
66

77
## Pull Requests
88

9-
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP CS Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer).
9+
- **[PER Coding Style 3.0](https://www.php-fig.org/per/coding-style/)** - The easiest way to apply the conventions is to run `./vendor/bin/php-cs-fixer fix --allow-risky=yes`.
1010
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
1111
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
1212
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"require-dev": {
3535
"mockery/mockery": "^1.6",
3636
"phpunit/phpunit": "^12.5 || ^13.0",
37-
"friendsofphp/php-cs-fixer": "^3.48",
37+
"friendsofphp/php-cs-fixer": "^3.95",
3838
"phpstan/phpstan": "^2.2"
3939
},
4040
"autoload": {

phpstan.neon

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
parameters:
22
level: 8
3+
treatPhpDocTypesAsCertain: false
34
paths:
45
- src/
5-
ignoreErrors:
6-
-
7-
identifier: missingType.iterableValue

scripts/generate-image.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
use League\Glide\ServerFactory;
2424

25-
require __DIR__.'/../vendor/autoload.php';
25+
require __DIR__ . '/../vendor/autoload.php';
2626

2727
/**
2828
* Translate legacy v0.3 Glide params to current equivalents.
@@ -40,10 +40,10 @@ function translateLegacyParams(array $params): array
4040

4141
// fit=crop & crop=left → fit=crop-left
4242
if (isset($params['fit'], $params['crop'])
43-
&& 'crop' === $params['fit']
43+
&& $params['fit'] === 'crop'
4444
&& !preg_match('/^\d/', $params['crop'])
4545
) {
46-
$params['fit'] = 'crop-'.$params['crop'];
46+
$params['fit'] = 'crop-' . $params['crop'];
4747
unset($params['crop']);
4848
}
4949

@@ -70,7 +70,7 @@ function buildOutputFilename(string $sourceImage, array $params): string
7070
}
7171

7272
if (empty($params)) {
73-
return $base.'.'.$ext;
73+
return $base . '.' . $ext;
7474
}
7575

7676
ksort($params);
@@ -85,10 +85,10 @@ function buildOutputFilename(string $sourceImage, array $params): string
8585
// Negative values → 'neg' (e.g. bri=-25 → bri-neg25)
8686
$safeValue = str_replace('-', 'neg', $safeValue);
8787

88-
$parts[] = $key.'-'.$safeValue;
88+
$parts[] = $key . '-' . $safeValue;
8989
}
9090

91-
return $base.'-'.implode('_', $parts).'.'.$ext;
91+
return $base . '-' . implode('_', $parts) . '.' . $ext;
9292
}
9393

9494
/**
@@ -114,14 +114,14 @@ function generateImage(string $input, string $sourceDir, string $outputDir): str
114114
$params = translateLegacyParams($params);
115115

116116
// Resolve source file
117-
$sourcePath = $sourceDir.'/'.$sourceImage;
117+
$sourcePath = $sourceDir . '/' . $sourceImage;
118118
if (!file_exists($sourcePath)) {
119119
throw new RuntimeException("Source image not found: {$sourcePath}");
120120
}
121121

122122
// Build output filename
123123
$outputFilename = buildOutputFilename($sourceImage, $params);
124-
$outputPath = $outputDir.'/'.$outputFilename;
124+
$outputPath = $outputDir . '/' . $outputFilename;
125125

126126
// Skip if already generated
127127
if (file_exists($outputPath)) {
@@ -153,8 +153,8 @@ function generateImage(string $input, string $sourceDir, string $outputDir): str
153153
exit(1);
154154
}
155155

156-
$sourceDir = __DIR__.'/../docs/source-images';
157-
$outputDir = __DIR__.'/../docs/images';
156+
$sourceDir = __DIR__ . '/../docs/source-images';
157+
$outputDir = __DIR__ . '/../docs/images';
158158

159159
try {
160160
$filename = generateImage($argv[1], $sourceDir, $outputDir);

src/Api/Api.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Api implements ApiInterface
2525
/**
2626
* Collection of manipulators.
2727
*
28-
* @var ManipulatorInterface[]
28+
* @var array<ManipulatorInterface>
2929
*/
3030
protected array $manipulators;
3131

@@ -45,8 +45,8 @@ class Api implements ApiInterface
4545
* Create API instance.
4646
*
4747
* @param ImageManagerInterface $imageManager Intervention image manager.
48-
* @param array $manipulators Collection of manipulators.
49-
* @param Encoder|null $encoder Image encoder.
48+
* @param array<ManipulatorInterface> $manipulators Collection of manipulators.
49+
* @param Encoder|null $encoder Image encoder.
5050
*/
5151
public function __construct(ImageManagerInterface $imageManager, array $manipulators, ?Encoder $encoder = null)
5252
{
@@ -79,7 +79,7 @@ public function getImageManager(): ImageManagerInterface
7979
/**
8080
* Set the manipulators.
8181
*
82-
* @param array $manipulators Collection of manipulators.
82+
* @param array<ManipulatorInterface> $manipulators Collection of manipulators.
8383
*/
8484
public function setManipulators(array $manipulators): void
8585
{
@@ -95,7 +95,7 @@ public function setManipulators(array $manipulators): void
9595
/**
9696
* Get the manipulators.
9797
*
98-
* @return array Collection of manipulators.
98+
* @return array<ManipulatorInterface> Collection of manipulators.
9999
*/
100100
public function getManipulators(): array
101101
{
@@ -125,8 +125,8 @@ public function getEncoder(): Encoder
125125
/**
126126
* Perform image manipulations.
127127
*
128-
* @param string $source Source image binary data.
129-
* @param array $params The manipulation params.
128+
* @param string $source Source image binary data.
129+
* @param array<string, mixed> $params The manipulation params.
130130
*
131131
* @return string Manipulated image binary data.
132132
*/
@@ -145,8 +145,8 @@ public function run(string $source, array $params): string
145145
/**
146146
* Perform image encoding to a given format.
147147
*
148-
* @param ImageInterface $image Image object
149-
* @param array $params the manipulator params
148+
* @param ImageInterface $image Image object
149+
* @param array<string, mixed> $params the manipulator params
150150
*
151151
* @return string Manipulated image binary data
152152
*/

src/Api/ApiInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ interface ApiInterface
99
/**
1010
* Perform image manipulations.
1111
*
12-
* @param string $source Source image binary data.
13-
* @param array $params The manipulation params.
12+
* @param string $source Source image binary data.
13+
* @param array<string, mixed> $params The manipulation params.
1414
*
1515
* @return string Manipulated image binary data.
1616
*/

src/Api/Encoder.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ class Encoder
1515
{
1616
/**
1717
* The manipulation params.
18+
*
19+
* @var array<string, mixed>
1820
*/
1921
protected array $params;
2022

2123
/**
2224
* Class constructor.
2325
*
24-
* @param array $params the manipulator params
26+
* @param array<string, mixed> $params the manipulator params
2527
*/
2628
public function __construct(array $params = [])
2729
{
@@ -31,7 +33,7 @@ public function __construct(array $params = [])
3133
/**
3234
* Set the manipulation params.
3335
*
34-
* @param array $params The manipulation params.
36+
* @param array<string, mixed> $params The manipulation params.
3537
*
3638
* @return $this
3739
*/
@@ -65,7 +67,7 @@ public function run(ImageInterface $image): EncodedImageInterface
6567
$quality = $this->getQuality();
6668
$shouldInterlace = filter_var($this->getParam('interlace'), FILTER_VALIDATE_BOOLEAN);
6769

68-
if ('pjpg' === $format) {
70+
if ($format === 'pjpg') {
6971
$shouldInterlace = true;
7072
$format = 'jpg';
7173
}
@@ -112,7 +114,7 @@ public function getFormat(ImageInterface $image): string
112114
}
113115

114116
$mediaType = MediaType::tryFrom($image->origin()->mediaType());
115-
if (null === $mediaType) {
117+
if ($mediaType === null) {
116118
return 'jpg';
117119
}
118120

src/Filesystem/FileNotFoundException.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@
44

55
namespace League\Glide\Filesystem;
66

7-
class FileNotFoundException extends \Exception
8-
{
9-
}
7+
class FileNotFoundException extends \Exception {}

0 commit comments

Comments
 (0)