Skip to content

Add php-cs-fixer as github action #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/static-code-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@ name: Static code analysis
on: [pull_request]

jobs:
static-code-analysis:
phpstan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Run PHPStan
uses: docker://jakzal/phpqa:php7.3-alpine
with:
args: phpstan analyze

php-cs-fixer:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Run PHP-CS-Fixer
uses: docker://jakzal/phpqa:php7.3-alpine
with:
args: php-cs-fixer fix --dry-run --diff-format udiff -vvv
24 changes: 14 additions & 10 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<?php

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

use SLLH\StyleCIBridge\ConfigBridge;

return ConfigBridge::create();
return $config;
17 changes: 15 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
.PHONY: ${TARGETS}

DIR := ${CURDIR}
QA_IMAGE := jakzal/phpqa:php7.3-alpine

static:
docker run --rm -v $(DIR):/project -w /project $(QA_IMAGE) phpstan analyze
cs-fix:
@docker run --rm -v $(DIR):/project -w /project $(QA_IMAGE) php-cs-fixer fix --diff-format udiff -vvv

cs-diff:
@docker run --rm -v $(DIR):/project -w /project $(QA_IMAGE) php-cs-fixer fix --diff-format udiff --dry-run -vvv

phpstan:
@docker run --rm -v $(DIR):/project -w /project $(QA_IMAGE) phpstan analyze

static: cs-diff phpstan

test: static
@vendor/bin/phpunit
16 changes: 0 additions & 16 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
parameters:
ignoreErrors:
-
message: "#^Method Translation\\\\SymfonyStorage\\\\FileStorage\\:\\:writeCatalogue\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/FileStorage.php

-
message: "#^Method Translation\\\\SymfonyStorage\\\\FileStorage\\:\\:writeCatalogue\\(\\) has parameter \\$locale with no typehint specified\\.$#"
count: 1
path: src/FileStorage.php

-
message: "#^Parameter \\#1 \\$catalogue of method Symfony\\\\Component\\\\Translation\\\\Writer\\\\TranslationWriterInterface\\:\\:write\\(\\) expects Symfony\\\\Component\\\\Translation\\\\MessageCatalogue, Symfony\\\\Component\\\\Translation\\\\MessageCatalogueInterface given\\.$#"
count: 2
path: src/FileStorage.php

-
message: "#^Method Translation\\\\SymfonyStorage\\\\FileStorage\\:\\:loadCatalogue\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/FileStorage.php

31 changes: 4 additions & 27 deletions src/FileStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,13 @@ final class FileStorage implements Storage, TransferableStorage
*/
private $catalogues;

/**
* @param TranslationWriterInterface $writer
* @param TranslationReaderInterface $reader
* @param array $dir
* @param array $options
*/
public function __construct(TranslationWriterInterface $writer, TranslationReaderInterface $reader, array $dir, array $options = [])
{
if (empty($dir)) {
throw new \LogicException('Third parameter of FileStorage cannot be empty');
}

if (!array_key_exists('xliff_version', $options)) {
if (!\array_key_exists('xliff_version', $options)) {
// Set default value for xliff version.
$options['xliff_version'] = '2.0';
}
Expand Down Expand Up @@ -141,13 +135,7 @@ public function import(MessageCatalogueInterface $catalogue, array $options = []
}
}

/**
* Save catalogue back to file.
*
* @param MessageCatalogueInterface $catalogue
* @param string $domain
*/
private function writeCatalogue(MessageCatalogueInterface $catalogue, $locale, $domain)
private function writeCatalogue(MessageCatalogueInterface $catalogue, string $locale, string $domain): void
{
$resources = $catalogue->getResources();
$options = $this->options;
Expand All @@ -171,12 +159,7 @@ private function writeCatalogue(MessageCatalogueInterface $catalogue, $locale, $
$this->writer->write($catalogue, $format, $options);
}

/**
* @param string $locale
*
* @return MessageCatalogue
*/
private function getCatalogue($locale)
private function getCatalogue(string $locale): MessageCatalogue
{
if (empty($this->catalogues[$locale])) {
$this->loadCatalogue($locale, $this->dir);
Expand All @@ -185,13 +168,7 @@ private function getCatalogue($locale)
return $this->catalogues[$locale];
}

/**
* Load catalogue from files.
*
* @param string $locale
* @param array $dirs
*/
private function loadCatalogue($locale, array $dirs)
private function loadCatalogue(string $locale, array $dirs): void
{
$currentCatalogue = new MessageCatalogue($locale);
foreach ($dirs as $path) {
Expand Down
19 changes: 3 additions & 16 deletions src/XliffConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,18 @@ final class XliffConverter
{
/**
* Create a catalogue from the contents of a XLIFF file.
*
* @param string $content
* @param string $locale
* @param string $domain
*
* @return MessageCatalogue
*/
public static function contentToCatalogue($content, $locale, $domain)
public static function contentToCatalogue(string $content, string $locale, string $domain): MessageCatalogue
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is a BC break. It's not a real problem as we're about to release a new major version anyway.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(same line 36)

{
$file = sys_get_temp_dir().'/'.uniqid('xliff', true);
file_put_contents($file, $content);

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

/**
* @param MessageCatalogue $catalogue
* @param string $domain
* @param array $options
*
* @return string
*/
public static function catalogueToContent(MessageCatalogue $catalogue, $domain, array $options = [])
public static function catalogueToContent(MessageCatalogue $catalogue, string $domain, array $options = []): string
{
if (!array_key_exists('xliff_version', $options)) {
if (!\array_key_exists('xliff_version', $options)) {
// Set default value for xliff version.
$options['xliff_version'] = '2.0';
}
Expand Down