Skip to content

Commit 862c540

Browse files
Initial commit
0 parents  commit 862c540

24 files changed

+1220
-0
lines changed

.gitattributes

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Define the line ending behavior of the different file extensions
2+
# Set default behaviour, in case users don't have core.autocrlf set.
3+
* text=auto
4+
* text eol=lf
5+
6+
# Explicitly declare text files we want to always be normalized and converted
7+
# to native line endings on checkout.
8+
*.default text
9+
*.example text
10+
*.json text
11+
*.md text
12+
*.php text
13+
*.txt text
14+
*.xml text
15+
*.yaml text
16+
*.yml text
17+
.gitignore text

.github/workflows/main.yml

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- release/*
8+
- issue-*
9+
pull_request:
10+
branches:
11+
- master
12+
schedule:
13+
- cron: 0 7 * * 1
14+
15+
jobs:
16+
analysis:
17+
runs-on: ubuntu-latest
18+
strategy:
19+
matrix:
20+
php: [7.4]
21+
steps:
22+
- uses: actions/checkout@v1
23+
- name: Cache composer dependencies
24+
uses: actions/cache@v2
25+
env:
26+
cache-name: cache-gcr-worker-laravel-latest
27+
with:
28+
path: ~/.composer
29+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.json') }}
30+
restore-keys: |
31+
${{ runner.os }}-build-${{ env.cache-name }}-
32+
${{ runner.os }}-build-
33+
${{ runner.os }}-
34+
- name: Install composer dependencies
35+
run: composer install --prefer-dist
36+
- name: Run phpstan analysis
37+
run: composer phpstan-analysis
38+
- name: Run phpmd analysis
39+
run: composer phpmd-analysis
40+
- name: Run phpcpd analysis
41+
run: vendor/bin/phpcpd --min-lines=3 --min-tokens=36 src/
42+
laravel57:
43+
needs: [ analysis ]
44+
runs-on: ubuntu-latest
45+
strategy:
46+
matrix:
47+
php: [ 7.2, 7.3, 7.4 ]
48+
steps:
49+
- uses: actions/checkout@v1
50+
- name: Update laravel version
51+
run: composer require "laravel/framework:5.7.*" "orchestra/testbench:3.7.*" --no-update
52+
- name: Remove some dev dependencies
53+
run: composer remove "ekino/phpstan-banned-code" "nunomaduro/larastan" "phpmd/phpmd" "phpstan/phpstan-deprecation-rules" "sebastian/phpcpd" --dev --no-update
54+
- name: Install composer dependencies
55+
run: composer install --prefer-dist
56+
- name: Run the test suite
57+
run: phpdbg -qrr -dmemory_limit=3G vendor/bin/phpunit
58+
laravel58:
59+
needs: [ analysis ]
60+
runs-on: ubuntu-latest
61+
strategy:
62+
matrix:
63+
php: [ 7.2, 7.3, 7.4 ]
64+
steps:
65+
- uses: actions/checkout@v1
66+
- name: Update laravel version
67+
run: composer require "laravel/framework:5.8.*" "orchestra/testbench:3.8.*" --no-update
68+
- name: Remove some dev dependencies
69+
run: composer remove "ekino/phpstan-banned-code" "nunomaduro/larastan" "phpmd/phpmd" "phpstan/phpstan-deprecation-rules" "sebastian/phpcpd" --dev --no-update
70+
- name: Install composer dependencies
71+
run: composer install --prefer-dist
72+
- name: Run the test suite
73+
run: phpdbg -qrr -dmemory_limit=3G vendor/bin/phpunit
74+
laravel60:
75+
needs: [ analysis ]
76+
runs-on: ubuntu-latest
77+
strategy:
78+
matrix:
79+
php: [ 7.2, 7.3, 7.4 ]
80+
steps:
81+
- uses: actions/checkout@v1
82+
- name: Update laravel version
83+
run: composer require "laravel/framework:^6.0" "orchestra/testbench:^4.0" --no-update
84+
- name: Remove some dev dependencies
85+
run: composer remove "ekino/phpstan-banned-code" "nunomaduro/larastan" "phpmd/phpmd" "phpstan/phpstan-deprecation-rules" "sebastian/phpcpd" --dev --no-update
86+
- name: Install composer dependencies
87+
run: composer install --prefer-dist
88+
- name: Run the test suite
89+
run: phpdbg -qrr -dmemory_limit=3G vendor/bin/phpunit
90+
laravel70:
91+
needs: [ analysis ]
92+
runs-on: ubuntu-latest
93+
strategy:
94+
matrix:
95+
php: [ 7.2, 7.3, 7.4 ]
96+
steps:
97+
- uses: actions/checkout@v1
98+
- name: Update laravel version
99+
run: composer require "laravel/framework:^7.0" "orchestra/testbench:^5.0" --no-update
100+
- name: Remove some dev dependencies
101+
run: composer remove "ekino/phpstan-banned-code" "nunomaduro/larastan" "phpmd/phpmd" "phpstan/phpstan-deprecation-rules" "sebastian/phpcpd" --dev --no-update
102+
- name: Install composer dependencies
103+
run: composer install --prefer-dist
104+
- name: Run the test suite
105+
run: phpdbg -qrr -dmemory_limit=3G vendor/bin/phpunit
106+
laravel80:
107+
needs: [analysis]
108+
runs-on: ubuntu-latest
109+
strategy:
110+
matrix:
111+
php: [7.4]
112+
steps:
113+
- uses: actions/checkout@v1
114+
- name: Cache composer dependencies
115+
uses: actions/cache@v2
116+
env:
117+
cache-name: cache-gcr-worker-laravel-latest
118+
with:
119+
path: ~/.composer
120+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.json') }}
121+
restore-keys: |
122+
${{ runner.os }}-build-${{ env.cache-name }}-
123+
${{ runner.os }}-build-
124+
${{ runner.os }}-
125+
- name: Install composer dependencies
126+
run: composer install --prefer-dist
127+
- name: Run the Coverage test suite
128+
run: phpdbg -qrr -dmemory_limit=3G vendor/bin/phpunit --coverage-clover=clover.xml
129+
- name: Upload test coverage report to codecov.io
130+
env:
131+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
132+
run: bash <(curl -s https://codecov.io/bash)

.gitignore

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# OS generated files
2+
# ----------------------------------------------------------------------- #
3+
4+
.DS_Store
5+
.DS_Store?
6+
._*
7+
.Spotlight-V100
8+
.Trashes
9+
Icon?
10+
ehthumbs.db
11+
Thumbs.db
12+
13+
14+
# Vagrant files
15+
# ----------------------------------------------------------------------- #
16+
17+
Vagrantfile
18+
.vagrant
19+
*.log
20+
21+
22+
# Code Editor / IDE generated files
23+
# ----------------------------------------------------------------------- #
24+
25+
.idea
26+
*.sublime-project
27+
*.sublime-workspace
28+
29+
30+
# Composer & Vendor Files
31+
# ----------------------------------------------------------------------- #
32+
33+
composer.phar
34+
composer.lock
35+
/vendor
36+
37+
38+
# Cache Files
39+
# ----------------------------------------------------------------------- #
40+
41+
*.cache
42+
43+
44+
# Other files
45+
# ----------------------------------------------------------------------- #
46+
47+
/coverage
48+

.phpmd.cleancode.xml

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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+
71+
<rule name="IfStatementAssignment"
72+
since="2.7.0"
73+
message="Avoid assigning values to variables in if clauses and the like (line '{0}', column '{1}')."
74+
class="PHPMD\Rule\CleanCode\IfStatementAssignment"
75+
externalInfoUrl="http://phpmd.org/rules/cleancode.html#ifstatementassignment">
76+
<description>
77+
<![CDATA[
78+
Assignments in if clauses and the like are considered a code smell.
79+
Assignments in PHP return the right operand as their result.
80+
In many cases, this is an expected behavior, but can lead
81+
to many difficult to spot bugs, especially when the right
82+
operand could result in zero, null or an empty string and the like.
83+
]]>
84+
</description>
85+
<priority>1</priority>
86+
<properties></properties>
87+
<example>
88+
<![CDATA[
89+
class Foo
90+
{
91+
public function bar($flag)
92+
{
93+
if ($foo = 'bar') { // possible typo
94+
// ...
95+
}
96+
if ($baz = 0) { // always false
97+
// ...
98+
}
99+
}
100+
}
101+
]]>
102+
</example>
103+
</rule>
104+
105+
<rule name="DuplicatedArrayKey"
106+
message="Duplicated array key {0}, first declared at line {1}."
107+
class="PHPMD\Rule\CleanCode\DuplicatedArrayKey"
108+
externalInfoUrl="http://phpmd.org/rules/cleancode.html#duplicatedarraykey">
109+
<description>
110+
<![CDATA[
111+
Defining another value for the same key in an array literal overrides the previous key/value,
112+
which makes it effectively an unused code. If it's known from the beginning that the key
113+
will have different value, there is usually no point in defining first one.
114+
]]>
115+
</description>
116+
<priority>2</priority>
117+
<example>
118+
<![CDATA[
119+
function createArray() {
120+
return [
121+
'non-associative 0element', // not applied
122+
0 => 'associative 0-element', // applied
123+
false => 'associative 0-element', // applied
124+
'foo' => 'bar', // not applied
125+
"foo" => 'baz', // applied
126+
];
127+
}
128+
]]>
129+
</example>
130+
</rule>
131+
132+
<rule name="MissingImport"
133+
since="2.7.0"
134+
message="Missing class import via use statement (line '{0}', column '{1}')."
135+
class="PHPMD\Rule\CleanCode\MissingImport"
136+
externalInfoUrl="http://phpmd.org/rules/cleancode.html#MissingImport">
137+
<description>
138+
<![CDATA[
139+
Importing all external classes in a file through use statements makes them clearly visible.
140+
]]>
141+
</description>
142+
<priority>1</priority>
143+
<example>
144+
<![CDATA[
145+
function make() {
146+
return new \stdClass();
147+
}
148+
]]>
149+
</example>
150+
</rule>
151+
</ruleset>

LICENSE.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# The MIT License (MIT)
2+
3+
Copyright (c) 2020 Richan Fongdasen <[email protected]>
4+
5+
> Permission is hereby granted, free of charge, to any person obtaining a copy
6+
> of this software and associated documentation files (the "Software"), to deal
7+
> in the Software without restriction, including without limitation the rights
8+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
> copies of the Software, and to permit persons to whom the Software is
10+
> furnished to do so, subject to the following conditions:
11+
>
12+
>
13+
> The above copyright notice and this permission notice shall be included in all
14+
> copies or substantial portions of the Software.
15+
>
16+
>
17+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
> SOFTWARE.
24+

0 commit comments

Comments
 (0)