Skip to content

Commit

Permalink
Support Laravel 9 (#3)
Browse files Browse the repository at this point in the history
* wip

* Update composer.json

* Update composer.json

Co-authored-by: Samuel Štancl <[email protected]>

* Update composer.json

Co-authored-by: Samuel Štancl <[email protected]>

* Update ci.yml

* Update composer.json

* wip

* wip

* Update ci.yml

* typehint -> type

* Update phpstan.neon

* Update composer.json

* Update composer.json

* wip

* Update composer.json

* Update composer.json

* Update composer.json

Co-authored-by: Samuel Štancl <[email protected]>
  • Loading branch information
abrardev99 and stancl authored Jan 27, 2022
1 parent 1b1eca8 commit 263e0aa
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 56 deletions.
26 changes: 16 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,25 @@ on:

jobs:
phpunit:
name: Tests (PHPUnit) L${{ matrix.laravel }}
runs-on: ubuntu-latest
strategy:
matrix:
laravel: [6, 8]

name: Tests (PHPUnit)
runs-on: ubuntu-latest
laravel: [6, 8, 9]

steps:
- uses: actions/checkout@v2
- name: Install composer dependencies
run: composer require "laravel/framework:^${{matrix.laravel}}.0.0"
- name: Run tests
run: vendor/bin/phpunit
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'

- name: Install dependencies
run: composer require "laravel/framework:^${{matrix.laravel}}.0"
- name: Run tests
run: vendor/bin/phpunit

phpstan:
name: Static analysis (PHPStan)
Expand All @@ -46,7 +52,7 @@ jobs:
- name: Install php-cs-fixer
run: composer global require friendsofphp/php-cs-fixer
- name: Run php-cs-fixer
run: $HOME/.composer/vendor/bin/php-cs-fixer fix --config=.php_cs.php
run: $HOME/.composer/vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php
- name: Commit changes from php-cs-fixer
uses: EndBug/add-and-commit@v5
with:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.phpunit.result.cache
composer.lock
vendor/
.php_cs.cache
.php-cs-fixer.cache
.vscode/
34 changes: 14 additions & 20 deletions .php_cs.php → .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,19 @@
'operators' => [
'=>' => null,
'|' => 'no_space',
]
],
],
'blank_line_after_namespace' => true,
'blank_line_after_opening_tag' => true,
'no_superfluous_phpdoc_tags' => true,
'blank_line_before_statement' => [
'statements' => ['return']
'statements' => ['return'],
],
'braces' => true,
'cast_spaces' => true,
'class_attributes_separation' => [
'elements' => ['method']
],
'class_definition' => true,
'concat_space' => [
'spacing' => 'one'
'spacing' => 'one',
],
'declare_equal_normalize' => true,
'elseif' => true,
Expand All @@ -42,7 +39,7 @@
'linebreak_after_opening_tag' => true,
'line_ending' => true,
'lowercase_cast' => true,
'lowercase_constants' => true,
'constant_case' => true,
'lowercase_keywords' => true,
'lowercase_static_reference' => true, // added from Symfony
'magic_method_casing' => true, // added from Symfony
Expand All @@ -56,7 +53,7 @@
'throw',
'use',
'use_trait',
]
],
],
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
Expand All @@ -66,11 +63,11 @@
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_mixed_echo_print' => [
'use' => 'echo'
'use' => 'echo',
],
'no_multiline_whitespace_around_double_arrow' => true,
'multiline_whitespace_before_semicolons' => [
'strategy' => 'no_multi_line'
'strategy' => 'no_multi_line',
],
'no_short_bool_cast' => true,
'no_singleline_whitespace_before_semicolons' => true,
Expand All @@ -89,9 +86,9 @@
'normalize_index_brace' => true,
'not_operator_with_successor_space' => true,
'object_operator_without_whitespace' => true,
'ordered_imports' => ['sortAlgorithm' => 'alpha'],
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'phpdoc_indent' => true,
'phpdoc_inline_tag' => true,
'general_phpdoc_tag_rename' => true,
'phpdoc_no_access' => true,
'phpdoc_no_package' => true,
'phpdoc_no_useless_inheritdoc' => true,
Expand All @@ -102,31 +99,28 @@
'phpdoc_trim' => true,
'phpdoc_types' => true,
'phpdoc_var_without_name' => true,
'psr4' => true,
'psr_autoloading' => true,
'self_accessor' => true,
'short_scalar_cast' => true,
'simplified_null_return' => false, // disabled by Shift
'single_blank_line_at_eof' => true,
'single_blank_line_before_namespace' => true,
'single_class_element_per_statement' => true,
'single_import_per_statement' => true,
'single_import_per_statement' => false,
'single_line_after_imports' => true,
'no_unused_imports' => true,
'single_line_comment_style' => [
'comment_types' => ['hash']
'comment_types' => ['hash'],
],
'single_quote' => true,
'space_after_semicolon' => true,
'standardize_not_equals' => true,
'switch_case_semicolon_to_colon' => true,
'switch_case_space' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline_array' => true,
'trailing_comma_in_multiline' => true,
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
// 'visibility_required' => [
// 'elements' => ['method', 'property']
// ],
'whitespace_after_comma_in_array' => true,
];

Expand All @@ -140,7 +134,7 @@
->ignoreDotFiles(true)
->ignoreVCS(true);

return Config::create()
return (new Config())
->setFinder($finder)
->setRules($rules)
->setRiskyAllowed(true)
Expand Down
54 changes: 54 additions & 0 deletions check
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash
set -e

offer_run() {
read -p "For more output, run $1. Run it now (Y/n)? " run

case ${run:0:1} in
n|N )
exit 1
;;
* )
$1
;;
esac

exit 1
}

if (php-cs-fixer fix --dry-run --config=.php-cs-fixer.php > /dev/null 2>/dev/null); then
echo '✅ php-cs-fixer OK'
else
read -p "⚠️ php-cs-fixer found issues. Fix (Y/n)? " fix
case ${fix:0:1} in
n|N )
echo '❌ php-cs-fixer FAIL'
offer_run 'php-cs-fixer fix --config=.php-cs-fixer.php'
;;
* )
if (php-cs-fixer fix --config=.php-cs-fixer.php > /dev/null 2>/dev/null); then
echo '✅ php-cs-fixer OK'
else
echo '❌ php-cs-fixer FAIL'
offer_run 'php-cs-fixer fix --config=.php-cs-fixer.php'
fi
;;
esac
fi

if (./vendor/bin/phpstan analyse > /dev/null 2>/dev/null); then
echo '✅ PHPStan OK'
else
echo '❌ PHPStan FAIL'
offer_run './vendor/bin/phpstan analyse'
fi

if (./vendor/bin/phpunit > /dev/null 2>/dev/null); then
echo '✅ PHPUnit OK'
else
echo '❌ PHPUnit FAIL'
offer_run './vendor/bin/phpunit'
fi

echo '=================='
echo '✅ Everything OK'
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
}
},
"require": {
"illuminate/translation": "^8.0||^6.0"
"illuminate/translation": "^6.0|^8.0|^9.0"
},
"require-dev": {
"orchestra/testbench": "^6.0||^4.0",
"orchestra/testbench": "^4.0|^6.0|^7.0",
"phpunit/phpunit": "^9.5",
"nunomaduro/larastan": "^0.6.11"
"nunomaduro/larastan": "^1.0"
},
"extra": {
"laravel": {
Expand All @@ -32,5 +32,7 @@
"Gloss": "Lean\\Gloss\\Gloss"
}
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
8 changes: 2 additions & 6 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ parameters:

ignoreErrors:
-
message: '#has no return typehint specified#'
message: '#has no return type specified#'
paths:
- tests/*
- src/GlossTranslator.php
Expand All @@ -22,11 +22,7 @@ parameters:
paths:
- tests/*
-
message: '#with no typehint specified#'
paths:
- src/GlossTranslator.php
-
message: '#of function str_replace expects#'
message: '#with no type specified#'
paths:
- src/GlossTranslator.php

Expand Down
17 changes: 5 additions & 12 deletions src/GlossTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class GlossTranslator extends Translator
/**
* Register an override that returns a different key name.
*
* @param string $shortKey
* @param string $newKey
* @param array|null|callable $condition
* @return void
*/
Expand All @@ -45,8 +43,6 @@ public function key(string $shortKey, string $newKey, $condition = null)
/**
* Register an override that returns a value.
*
* @param string $shortKey
* @param string $value
* @param array|null|callable $condition
* @return void
*/
Expand All @@ -67,7 +63,6 @@ public function value(string $shortKey, string $value, $condition = null)
/**
* Register multiple value overrides.
*
* @param array $values
* @param array|null|callable $condition
* @return void
*/
Expand All @@ -82,8 +77,6 @@ public function values(array $values, $condition = null)
/**
* Customize a translation string's value using a callback.
*
* @param string $shortKey
* @param callable $value
* @return void
*/
public function extend(string $shortKey, callable $value)
Expand All @@ -95,7 +88,6 @@ public function extend(string $shortKey, callable $value)
* Get a translation string.
*
* @param string $key
* @param array $replace
* @param string|null $locale
* @param bool $fallback
* @return string
Expand Down Expand Up @@ -132,7 +124,6 @@ public function get($key, array $replace = [], $locale = null, $fallback = true)
/**
* Get a translation string and skip extensions.
*
* @param string $key
* @param array $replace
* @param string|null $locale
* @param bool $fallback
Expand Down Expand Up @@ -203,7 +194,9 @@ public function choice($key, $number, array $replace = [], $locale = null)
protected function choiceWithoutExtensions($key, $number, array $replace = [], $locale = null)
{
$line = $this->getWithoutExtensions(
$key, $replace, $locale = $this->localeForChoice($locale)
$key,
$replace,
$locale = $this->localeForChoice($locale)
);

// If the given "number" is actually an array or countable we will simply count the
Expand All @@ -216,7 +209,8 @@ protected function choiceWithoutExtensions($key, $number, array $replace = [], $
$replace['count'] = $number;

return $this->makeReplacements(
$this->getSelector()->choose($line, $number, $locale), $replace
$this->getSelector()->choose($line, $number, $locale),
$replace
);
}

Expand Down Expand Up @@ -252,7 +246,6 @@ protected function makeReplacementsInArray(array $lines, array $replace): array

/**
* @param string|callable $line
* @param array $replace
* @return string
*/
protected function makeReplacements($line, array $replace)
Expand Down
3 changes: 0 additions & 3 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*
* @param string|array|null $key
* @param array|callable|null $replace
* @param string|null $locale
* @return void|string|null|\Lean\Gloss\GlossTranslator
*/
function gloss($key = null, $replace = null, string $locale = null)
Expand All @@ -36,8 +35,6 @@ function gloss($key = null, $replace = null, string $locale = null)
* Resolve a translation string or Gloss instance.
*
* @param string|array|null $key
* @param array $replace
* @param string|null $locale
* @return void|string|null|\Lean\Gloss\GlossTranslator
*/
function ___($key = null, array $replace = [], string $locale = null)
Expand Down

0 comments on commit 263e0aa

Please sign in to comment.