Skip to content

Commit 0962fbb

Browse files
Add support for Laravel 8 (#19)
* Add support for Laravel 8 * Apply fixes from StyleCI
1 parent 79fc5f7 commit 0962fbb

38 files changed

+426
-169
lines changed

.phpmd.cleancode.xml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version="1.0"?>
2+
3+
<ruleset name="Clean Code Rules"
4+
xmlns="http://pmd.sf.net/ruleset/1.0.0"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
7+
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
8+
9+
<description>
10+
The Clean Code ruleset contains rules that enforce a clean code base. This includes rules from SOLID and object calisthenics.
11+
</description>
12+
13+
<rule name="BooleanArgumentFlag"
14+
since="1.4.0"
15+
message="The method {0} has a boolean flag argument {1}, which is a certain sign of a Single Responsibility Principle violation."
16+
class="PHPMD\Rule\CleanCode\BooleanArgumentFlag"
17+
externalInfoUrl="https://phpmd.org/rules/cleancode.html#booleanargumentflag">
18+
<description>
19+
<![CDATA[
20+
A boolean flag argument is a reliable indicator for a violation of
21+
the Single Responsibility Principle (SRP). You can fix this problem
22+
by extracting the logic in the boolean flag into its own class
23+
or method.
24+
]]>
25+
</description>
26+
<priority>1</priority>
27+
<properties />
28+
<example>
29+
<![CDATA[
30+
class Foo {
31+
public function bar($flag = true) {
32+
}
33+
}
34+
]]>
35+
</example>
36+
</rule>
37+
38+
<rule name="ElseExpression"
39+
since="1.4.0"
40+
message="The method {0} uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them."
41+
class="PHPMD\Rule\CleanCode\ElseExpression"
42+
externalInfoUrl="https://phpmd.org/rules/cleancode.html#elseexpression">
43+
<description>
44+
<![CDATA[
45+
An if expression with an else branch is basically not necessary. You can rewrite the
46+
conditions in a way that the else clause is not necessary and the code becomes simpler
47+
to read. To achieve this, use early return statements, though you may
48+
need to split the code it several smaller methods. For very simple assignments
49+
you could also use the ternary operations.
50+
]]>
51+
</description>
52+
<priority>1</priority>
53+
<properties/>
54+
<example>
55+
<![CDATA[
56+
class Foo
57+
{
58+
public function bar($flag)
59+
{
60+
if ($flag) {
61+
// one branch
62+
} else {
63+
// another branch
64+
}
65+
}
66+
}
67+
]]>
68+
</example>
69+
</rule>
70+
</ruleset>

.travis.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,10 @@ dist: bionic
55
matrix:
66
fast_finish: true
77
include:
8-
- php: 7.2
9-
env: LARAVEL=5.8.* ORCHESTRA=3.8.*
108
- php: 7.3
11-
env: LARAVEL=^6.0 ORCHESTRA=^4.0
9+
env: LARAVEL=^8.0 ORCHESTRA=^6.0
1210
- php: 7.4
13-
env: LARAVEL=^6.0 ORCHESTRA=^4.0
14-
- php: 7.3
15-
env: LARAVEL=^7.0 ORCHESTRA=^5.0
16-
- php: 7.4
17-
env: LARAVEL=^7.0 ORCHESTRA=^5.0 COVERAGE=1
11+
env: LARAVEL=^8.0 ORCHESTRA=^6.0 COVERAGE=1
1812

1913
allow_failures:
2014
- env: COVERAGE=1

composer.json

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,23 @@
2727
"source": "https://github.com/richan-fongdasen/laravel-i18n"
2828
},
2929
"require": {
30-
"php": "^7.2",
31-
"illuminate/database": "5.8.*|^6.0|^7.0",
32-
"illuminate/support": "5.8.*|^6.0|^7.0",
33-
"nesbot/carbon": "^2.0"
30+
"php": "^7.3",
31+
"illuminate/database": "^8.0",
32+
"illuminate/support": "^8.0",
33+
"nesbot/carbon": "^2.16"
3434
},
3535
"require-dev": {
36-
"fzaninotto/faker": "^1.4",
37-
"mockery/mockery": "^1.0",
38-
"orchestra/testbench": "~3.8|~4.0|~5.0",
39-
"orchestra/database": "~3.8|~4.0|~5.0",
40-
"phpunit/phpunit": "^7.5|^8.0|^9.0"
36+
"ekino/phpstan-banned-code": "^0.3",
37+
"fzaninotto/faker": "^1.9",
38+
"mockery/mockery": "^1.3",
39+
"nunomaduro/larastan": "^0.6.4",
40+
"orchestra/database": "^6.0",
41+
"orchestra/testbench": "^6.0",
42+
"phpmd/phpmd": "^2.9",
43+
"phpstan/phpstan": "^0.12",
44+
"phpstan/phpstan-deprecation-rules": "^0.12",
45+
"phpunit/phpunit": "^9.3",
46+
"sebastian/phpcpd": "^6.0"
4147
},
4248
"config": {
4349
"sort-packages": true
@@ -49,7 +55,8 @@
4955
},
5056
"autoload-dev": {
5157
"psr-4": {
52-
"RichanFongdasen\\I18n\\Tests\\": "tests/"
58+
"RichanFongdasen\\I18n\\Tests\\": "tests/",
59+
"Database\\Factories\\": "tests/Supports/Factories/"
5360
}
5461
},
5562
"extra": {
@@ -62,6 +69,33 @@
6269
}
6370
}
6471
},
72+
"scripts": {
73+
"analyse": [
74+
"composer check-syntax",
75+
"composer phpstan-analysis",
76+
"composer phpmd-analysis",
77+
"vendor/bin/phpcpd --min-lines=3 --min-tokens=36 src/"
78+
],
79+
"check-syntax": [
80+
"! find src -type f -name \"*.php\" -exec php -l {} \\; | grep -v 'No syntax errors'",
81+
"! find tests -type f -name \"*.php\" -exec php -l {} \\; | grep -v 'No syntax errors'"
82+
],
83+
"phpstan-analysis": [
84+
"vendor/bin/phpstan analyse -c phpstan.neon --no-progress"
85+
],
86+
"phpmd-analysis": [
87+
"vendor/bin/phpmd src text codesize,controversial,design,naming,unusedcode,.phpmd.cleancode.xml"
88+
],
89+
"cov-text": [
90+
"phpdbg -dmemory_limit=-1 -qrr vendor/bin/phpunit --coverage-text"
91+
],
92+
"cov-html": [
93+
"phpdbg -dmemory_limit=-1 -qrr vendor/bin/phpunit --coverage-html coverage"
94+
],
95+
"test": [
96+
"vendor/bin/phpunit"
97+
]
98+
},
6599
"minimum-stability": "dev",
66100
"prefer-stable": true
67101
}

phpstan.neon

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
includes:
2+
- vendor/nunomaduro/larastan/extension.neon
3+
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
4+
- vendor/ekino/phpstan-banned-code/extension.neon
5+
6+
parameters:
7+
level: max
8+
checkMissingIterableValueType: false
9+
paths:
10+
- src
11+
ignoreErrors:
12+
- '#Call to an undefined method RichanFongdasen\\I18n\\ServiceProvider::each\(\).#'
13+
banned_code:
14+
nodes:
15+
- type: Expr_FuncCall
16+
functions:
17+
- dd
18+
- debug_backtrace
19+
- die
20+
- dump
21+
- echo
22+
- eval
23+
- exec
24+
- exit
25+
- passthru
26+
- phpinfo
27+
- print_r
28+
- proc_open
29+
- shell_exec
30+
- system
31+
- var_dump

phpunit.xml

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit
3-
backupGlobals="false"
4-
backupStaticAttributes="false"
5-
bootstrap="vendor/autoload.php"
6-
colors="true"
7-
convertErrorsToExceptions="true"
8-
convertNoticesToExceptions="true"
9-
convertWarningsToExceptions="true"
10-
processIsolation="false"
11-
stopOnFailure="true">
12-
<testsuites>
13-
<testsuite name="Laravel I18n Test Suite">
14-
<directory suffix="Tests.php">./tests/</directory>
15-
</testsuite>
16-
</testsuites>
17-
<filter>
18-
<whitelist>
19-
<directory suffix=".php">src/</directory>
20-
</whitelist>
21-
</filter>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3+
<coverage>
4+
<include>
5+
<directory suffix=".php">src/</directory>
6+
</include>
7+
</coverage>
8+
<testsuites>
9+
<testsuite name="Laravel I18n Test Suite">
10+
<directory suffix="Tests.php">./tests/</directory>
11+
</testsuite>
12+
</testsuites>
2213
</phpunit>

readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ $ composer require richan-fongdasen/laravel-i18n
3737
5.1.x | 1.0.x
3838
5.2.x - 5.4.x | 1.1.x
3939
5.5.x - 5.8.x | 1.2.x
40+
6.x | 1.3.x
41+
7.x | 1.4.x
42+
8.x | 1.5.x
4043

4144
> If you are using Laravel version 5.5+ then you can skip registering the service provider in your Laravel application.
4245

src/Contracts/LanguageNegotiator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace RichanFongdasen\I18n\Contracts;
44

55
use Illuminate\Http\Request;
6+
use RichanFongdasen\I18n\Locale;
67

78
interface LanguageNegotiator
89
{
@@ -13,5 +14,5 @@ interface LanguageNegotiator
1314
*
1415
* @return \RichanFongdasen\I18n\Locale
1516
*/
16-
public function preferredLocale(Request $request);
17+
public function preferredLocale(Request $request): Locale;
1718
}

src/Contracts/TranslateableModel.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace RichanFongdasen\I18n\Contracts;
4+
5+
interface TranslateableModel
6+
{
7+
/**
8+
* Get an attribute from the model.
9+
*
10+
* @param string $key
11+
*
12+
* @return mixed
13+
*/
14+
public function getAttribute($key);
15+
16+
/**
17+
* Get the default foreign key name for the model.
18+
*
19+
* @return string
20+
*/
21+
public function getForeignKey();
22+
23+
/**
24+
* Get the value of the model's primary key.
25+
*
26+
* @return mixed
27+
*/
28+
public function getKey();
29+
30+
/**
31+
* Get translation table.
32+
*
33+
* @return string
34+
*/
35+
public function getTranslationTable(): string;
36+
37+
/**
38+
* Determine if the model or any of the given attribute(s) have been modified.
39+
*
40+
* @param array|string|null $attributes
41+
*
42+
* @return bool
43+
*/
44+
public function isDirty($attributes = null);
45+
}

0 commit comments

Comments
 (0)