Skip to content

Commit 2d7f883

Browse files
author
Olivier Dolbeau
committed
Add php-cs-fixer as github action
1 parent 80dd8e7 commit 2d7f883

File tree

6 files changed

+46
-72
lines changed

6 files changed

+46
-72
lines changed

.github/workflows/static-code-analysis.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@ name: Static code analysis
33
on: [pull_request]
44

55
jobs:
6-
static-code-analysis:
6+
phpstan:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@master
1010
- name: Run PHPStan
1111
uses: docker://jakzal/phpqa:php7.3-alpine
1212
with:
1313
args: phpstan analyze
14+
15+
php-cs-fixer:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@master
19+
- name: Run PHP-CS-Fixer
20+
uses: docker://jakzal/phpqa:php7.3-alpine
21+
with:
22+
args: php-cs-fixer fix --dry-run --diff-format udiff -vvv

.php_cs

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
<?php
22

3-
/*
4-
* In order to make it work, fabpot/php-cs-fixer and sllh/php-cs-fixer-styleci-bridge must be installed globally
5-
* with composer.
6-
*
7-
* @link https://github.com/Soullivaneuh/php-cs-fixer-styleci-bridge
8-
* @link https://github.com/FriendsOfPHP/PHP-CS-Fixer
9-
*/
3+
$config = PhpCsFixer\Config::create()
4+
->setRiskyAllowed(true)
5+
->setRules([
6+
'@Symfony' => true,
7+
'@Symfony:risky' => true,
8+
])
9+
->setFinder(
10+
PhpCsFixer\Finder::create()
11+
->in(__DIR__)
12+
->exclude(__DIR__.'/vendor')
13+
->name('*.php')
14+
)
15+
;
1016

11-
use SLLH\StyleCIBridge\ConfigBridge;
12-
13-
return ConfigBridge::create();
17+
return $config;

Makefile

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1+
.PHONY: ${TARGETS}
2+
13
DIR := ${CURDIR}
24
QA_IMAGE := jakzal/phpqa:php7.3-alpine
35

4-
static:
5-
docker run --rm -v $(DIR):/project -w /project $(QA_IMAGE) phpstan analyze
6+
cs-fix:
7+
@docker run --rm -v $(DIR):/project -w /project $(QA_IMAGE) php-cs-fixer fix --diff-format udiff -vvv
8+
9+
cs-diff:
10+
@docker run --rm -v $(DIR):/project -w /project $(QA_IMAGE) php-cs-fixer fix --diff-format udiff --dry-run -vvv
11+
12+
phpstan:
13+
@docker run --rm -v $(DIR):/project -w /project $(QA_IMAGE) phpstan analyze
14+
15+
static: cs-diff phpstan
16+
17+
test: static
18+
@vendor/bin/phpunit

phpstan-baseline.neon

-16
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,6 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: "#^Method Translation\\\\SymfonyStorage\\\\FileStorage\\:\\:writeCatalogue\\(\\) has no return typehint specified\\.$#"
5-
count: 1
6-
path: src/FileStorage.php
7-
8-
-
9-
message: "#^Method Translation\\\\SymfonyStorage\\\\FileStorage\\:\\:writeCatalogue\\(\\) has parameter \\$locale with no typehint specified\\.$#"
10-
count: 1
11-
path: src/FileStorage.php
12-
133
-
144
message: "#^Parameter \\#1 \\$catalogue of method Symfony\\\\Component\\\\Translation\\\\Writer\\\\TranslationWriterInterface\\:\\:write\\(\\) expects Symfony\\\\Component\\\\Translation\\\\MessageCatalogue, Symfony\\\\Component\\\\Translation\\\\MessageCatalogueInterface given\\.$#"
155
count: 2
166
path: src/FileStorage.php
17-
18-
-
19-
message: "#^Method Translation\\\\SymfonyStorage\\\\FileStorage\\:\\:loadCatalogue\\(\\) has no return typehint specified\\.$#"
20-
count: 1
21-
path: src/FileStorage.php
22-

src/FileStorage.php

+4-27
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,13 @@ final class FileStorage implements Storage, TransferableStorage
5252
*/
5353
private $catalogues;
5454

55-
/**
56-
* @param TranslationWriterInterface $writer
57-
* @param TranslationReaderInterface $reader
58-
* @param array $dir
59-
* @param array $options
60-
*/
6155
public function __construct(TranslationWriterInterface $writer, TranslationReaderInterface $reader, array $dir, array $options = [])
6256
{
6357
if (empty($dir)) {
6458
throw new \LogicException('Third parameter of FileStorage cannot be empty');
6559
}
6660

67-
if (!array_key_exists('xliff_version', $options)) {
61+
if (!\array_key_exists('xliff_version', $options)) {
6862
// Set default value for xliff version.
6963
$options['xliff_version'] = '2.0';
7064
}
@@ -141,13 +135,7 @@ public function import(MessageCatalogueInterface $catalogue, array $options = []
141135
}
142136
}
143137

144-
/**
145-
* Save catalogue back to file.
146-
*
147-
* @param MessageCatalogueInterface $catalogue
148-
* @param string $domain
149-
*/
150-
private function writeCatalogue(MessageCatalogueInterface $catalogue, $locale, $domain)
138+
private function writeCatalogue(MessageCatalogueInterface $catalogue, string $locale, string $domain): void
151139
{
152140
$resources = $catalogue->getResources();
153141
$options = $this->options;
@@ -171,12 +159,7 @@ private function writeCatalogue(MessageCatalogueInterface $catalogue, $locale, $
171159
$this->writer->write($catalogue, $format, $options);
172160
}
173161

174-
/**
175-
* @param string $locale
176-
*
177-
* @return MessageCatalogue
178-
*/
179-
private function getCatalogue($locale)
162+
private function getCatalogue(string $locale): MessageCatalogue
180163
{
181164
if (empty($this->catalogues[$locale])) {
182165
$this->loadCatalogue($locale, $this->dir);
@@ -185,13 +168,7 @@ private function getCatalogue($locale)
185168
return $this->catalogues[$locale];
186169
}
187170

188-
/**
189-
* Load catalogue from files.
190-
*
191-
* @param string $locale
192-
* @param array $dirs
193-
*/
194-
private function loadCatalogue($locale, array $dirs)
171+
private function loadCatalogue(string $locale, array $dirs): void
195172
{
196173
$currentCatalogue = new MessageCatalogue($locale);
197174
foreach ($dirs as $path) {

src/XliffConverter.php

+3-16
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,18 @@ final class XliffConverter
2424
{
2525
/**
2626
* Create a catalogue from the contents of a XLIFF file.
27-
*
28-
* @param string $content
29-
* @param string $locale
30-
* @param string $domain
31-
*
32-
* @return MessageCatalogue
3327
*/
34-
public static function contentToCatalogue($content, $locale, $domain)
28+
public static function contentToCatalogue(string $content, string $locale, string $domain): MessageCatalogue
3529
{
3630
$file = sys_get_temp_dir().'/'.uniqid('xliff', true);
3731
file_put_contents($file, $content);
3832

3933
return (new XliffFileLoader())->load($file, $locale, $domain);
4034
}
4135

42-
/**
43-
* @param MessageCatalogue $catalogue
44-
* @param string $domain
45-
* @param array $options
46-
*
47-
* @return string
48-
*/
49-
public static function catalogueToContent(MessageCatalogue $catalogue, $domain, array $options = [])
36+
public static function catalogueToContent(MessageCatalogue $catalogue, string $domain, array $options = []): string
5037
{
51-
if (!array_key_exists('xliff_version', $options)) {
38+
if (!\array_key_exists('xliff_version', $options)) {
5239
// Set default value for xliff version.
5340
$options['xliff_version'] = '2.0';
5441
}

0 commit comments

Comments
 (0)