Skip to content

Commit 7178b5e

Browse files
committed
Refactor codes
- src/Number.php - src/Prime.php - src/Divisor.php - src/Multiple.php - src/Euclid.php - src/Fraction.php - src/Bezout.php Tests needed. Updating README needed.
1 parent 59846bd commit 7178b5e

31 files changed

Lines changed: 3579 additions & 228 deletions
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Set Tag to Merged Pull Request
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
types:
8+
- closed
9+
10+
jobs:
11+
set-tag:
12+
name: Get tags, Check and Set tag
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
16+
17+
steps:
18+
- name: Set up PHP
19+
uses: shivammathur/setup-php@v2
20+
with:
21+
php-version: 8.2
22+
coverage: xdebug
23+
tools: composer:v2
24+
25+
- name: Checkout code
26+
uses: actions/checkout@v3
27+
with:
28+
fetch-depth: 0
29+
30+
- name: PHP Version Check
31+
run: php -v
32+
33+
- name: Validate Composer JSON
34+
run: composer validate
35+
36+
- name: Get Version From Comopser JSON
37+
id: new-version
38+
run: |
39+
echo version=$(cat composer.json | grep version | head -1 | grep -Po '\d+\.\d+\.\d+') >> $GITHUB_OUTPUT
40+
41+
- name: Show New Version
42+
run: echo "version=${{ steps.new-version.outputs.version}}"
43+
44+
- name: Show Tags
45+
run: git tag
46+
47+
- name: Check If The Version Is Not In The Tag List
48+
run: |
49+
for tag in `git tag`
50+
do
51+
if [ $tag = ${{ steps.new-version.outputs.version }} ]; then
52+
echo "version ${{ steps.new-version.outputs.version }} already exists."
53+
exit 1
54+
fi
55+
done
56+
echo "[OK.]"
57+
58+
- name: Set tag
59+
run: |
60+
git tag ${{ steps.new-version.outputs.version }}
61+
git push origin ${{ steps.new-version.outputs.version }}
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
name: Test and Static Analysis (Pull Request)
2+
3+
on: pull_request
4+
5+
jobs:
6+
check-version-in-composer-json:
7+
name: Check Version
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Set up PHP
12+
uses: shivammathur/setup-php@v2
13+
with:
14+
php-version: 8.2
15+
tools: composer:v2
16+
17+
- name: Checkout code
18+
uses: actions/checkout@v3
19+
with:
20+
fetch-depth: 0
21+
22+
- name: PHP Version Check
23+
run: php -v
24+
25+
- name: Validate Composer JSON
26+
run: composer validate
27+
28+
- name: Get Version From Comopser JSON
29+
id: new-version
30+
run: |
31+
echo version=$(cat composer.json | grep version | head -1 | grep -Po '\d+\.\d+\.\d+') >> $GITHUB_OUTPUT
32+
33+
- name: Show New Version
34+
run: echo "version=${{ steps.new-version.outputs.version }}"
35+
36+
- name: Show Tags
37+
run: git tag
38+
39+
- name: Check If The Version Is Not In The Tag List
40+
run: |
41+
for tag in `git tag`
42+
do
43+
if [ $tag = ${{ steps.new-version.outputs.version }} ]; then
44+
echo "version ${{ steps.new-version.outputs.version }} already exists."
45+
exit 1
46+
fi
47+
done
48+
echo "OK."
49+
50+
test-and-static-analysis:
51+
name: Test and Lint
52+
runs-on: ubuntu-latest
53+
strategy:
54+
matrix:
55+
php: ['8.1', '8.2', '8.3']
56+
57+
steps:
58+
- name: Set up PHP
59+
uses: shivammathur/setup-php@v2
60+
with:
61+
php-version: ${{ matrix.php }}
62+
coverage: xdebug
63+
tools: composer:v2
64+
65+
- name: Set up Node
66+
uses: actions/setup-node@v3
67+
with:
68+
node-version: '14.x'
69+
70+
- name: Checkout code
71+
uses: actions/checkout@v3
72+
with:
73+
fetch-depth: 0
74+
75+
- name: PHP Version Check
76+
run: php -v
77+
78+
- name: Validate Composer JSON
79+
run: composer validate
80+
81+
- name: Run Composer Install
82+
id: composerinstall
83+
run: composer install --no-interaction
84+
85+
- name: PHP Lint
86+
run: ./vendor/bin/parallel-lint src tests examples
87+
88+
- name: Neon Lint
89+
run: ./vendor/nette/neon/bin/neon-lint conf
90+
91+
- name: PHP MD
92+
run: |
93+
./vendor/bin/phpmd --version
94+
./vendor/bin/phpmd ./src/ ./examples/ ./tests/ text phpmd.xml
95+
96+
- name: PHP Code Sniffer
97+
run: |
98+
./vendor/bin/phpcs --version
99+
./vendor/bin/phpcs --ignore=vendor --standard=phpcs.xml -s -p .
100+
101+
- name: PHPStan
102+
run: |
103+
./vendor/bin/phpstan --version
104+
./vendor/bin/phpstan analyze -c phpstan.neon
105+
106+
- name: Unit tests
107+
run: |
108+
mkdir -p build/logs
109+
./vendor/bin/phpunit --version
110+
echo "Test suite All"
111+
./vendor/bin/phpunit ./tests/
112+
113+
code-coverage:
114+
name: Code coverage
115+
runs-on: ubuntu-latest
116+
strategy:
117+
matrix:
118+
php: ['8.1']
119+
120+
steps:
121+
- name: Set up PHP
122+
uses: shivammathur/setup-php@v2
123+
with:
124+
php-version: ${{ matrix.php }}
125+
coverage: xdebug
126+
tools: composer:v2
127+
128+
- name: Set up Node
129+
uses: actions/setup-node@v3
130+
with:
131+
node-version: '14.x'
132+
133+
- name: Checkout code
134+
uses: actions/checkout@v3
135+
with:
136+
fetch-depth: 0
137+
138+
- name: Run Composer
139+
run: composer install --no-interaction
140+
141+
- name: Update PHPUnit for Code Coverage
142+
run: composer require phpunit/phpunit:^9.6 phploc/phploc:* sebastian/version:* --with-all-dependencies
143+
144+
- name: PHP Lint
145+
run: ./vendor/bin/parallel-lint src tests examples
146+
147+
- name: Unit tests
148+
run: |
149+
mkdir -p build/logs
150+
./vendor/bin/phpunit ./tests/ --coverage-clover build/logs/clover.xml

.php-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8.1

PHP_VERSIONS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
8.3
2+
8.2
3+
8.1

bin/CheckVersion.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/bash
2+
3+
# Script to check
4+
# if the version in composer.json
5+
# is not in git tags
6+
7+
if [ ! -r composer.json ]; then
8+
echo "composer.json not found."
9+
echo "operation aborted."
10+
exit 1
11+
fi
12+
13+
VERSION=$(cat composer.json | grep version | head -1 | grep -Po '\d+\.\d+\.\d+')
14+
printf 'version in composer.json: \033[1;33m%s\033[m\n' $VERSION
15+
16+
17+
show_latest_tags() {
18+
echo "The latest $1 tags are:"
19+
for tag in `git tag | sort | tail -$1`
20+
do
21+
printf '\033[93m%s\033[m\n' $tag
22+
done
23+
}
24+
25+
for tag in `git tag`
26+
do
27+
if [ $tag = $VERSION ]; then
28+
printf '\033[41m Error! version %s already exists in git tags. \033[m\n' $VERSION
29+
show_latest_tags 3
30+
exit 1
31+
fi
32+
done
33+
printf '\033[1;102m%s\033[m\n' " OK! versoin $VERSION is not in git tags. "
34+
show_latest_tags 3
35+
printf '\033[93m%s\033[m\n' "Don't forget to run \`composer update\` before commit."

bin/TestAndLint.sh

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/bash
2+
3+
# Script to Test and Lint
4+
# - for the repository: macocci7/php-scatterplot
5+
# requirement:
6+
# - phpenv/phpenv
7+
# - PHP versions defined in ../PHP_VERSIONS installed
8+
9+
CMD=phpenv
10+
$CMD -v &> /dev/null
11+
if [ $? -ne 0 ]; then
12+
echo "command [${CMD}] not found!"
13+
exit 1
14+
fi
15+
echo "-----------------------------------------------------------"
16+
echo "[composer validate]"
17+
composer validate
18+
if [ $? -ne 0 ]; then
19+
echo "Operation aborted."
20+
exit 1
21+
fi
22+
23+
test_and_lint() {
24+
echo "==========================================================="
25+
echo "[PHP $1][phpenv local $1]"
26+
phpenv local $1
27+
if [ $? -ne 0 ]; then
28+
echo "Failed to switch version to $i. skipped."
29+
return 1
30+
fi
31+
echo "-----------------------------------------------------------"
32+
echo "[PHP $1][php -v]"
33+
php -v
34+
echo "-----------------------------------------------------------"
35+
echo "[PHP $1][parallel-lint]"
36+
./vendor/bin/parallel-lint src tests examples
37+
echo "-----------------------------------------------------------"
38+
echo "[PHP $1][neon-lint]"
39+
./vendor/nette/neon/bin/neon-lint conf
40+
echo "-----------------------------------------------------------"
41+
echo "[PHP $1][phpcs]"
42+
./vendor/bin/phpcs --ignore=vendor \
43+
--standard=phpcs.xml \
44+
-p \
45+
-s \
46+
.
47+
echo "-----------------------------------------------------------"
48+
echo "[PHP $1][phpmd]"
49+
./vendor/bin/phpmd \
50+
./src/ ./examples/ ./tests/ text \
51+
phpmd.xml
52+
echo "-----------------------------------------------------------"
53+
echo "[PHP $1][phpstan]"
54+
./vendor/bin/phpstan analyze -c phpstan.neon
55+
echo "-----------------------------------------------------------"
56+
echo "[PHP $1][phpunit]"
57+
./vendor/bin/phpunit ./tests/ \
58+
--color auto
59+
echo "-----------------------------------------------------------"
60+
}
61+
62+
echo "[[TesAndLint.sh]]"
63+
64+
SUPPORTED_PHP_VERSIONS=PHP_VERSIONS
65+
if [ ! -f $SUPPORTED_PHP_VERSIONS ]; then
66+
echo "file [$SUPPORTED_PHP_VERSIONS] not found."
67+
echo "operation aborted."
68+
exit 1
69+
fi
70+
if [ ! -r $SUPPORTED_PHP_VERSIONS ]; then
71+
echo "cannot read file[$SUPPORTED_PHP_VERSIONS]."
72+
echo "operation aborted."
73+
exit 1
74+
fi
75+
STR_CMD=''
76+
while read version ; do
77+
STR_CMD="$STR_CMD test_and_lint $version;"
78+
done < $SUPPORTED_PHP_VERSIONS
79+
eval $STR_CMD

composer.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "macocci7/php-math-integer",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "PHP Math Library of the subjects of number theory(only natural number).",
55
"type": "library",
66
"license": "MIT",
@@ -17,6 +17,11 @@
1717
],
1818
"minimum-stability": "stable",
1919
"require-dev": {
20-
"squizlabs/php_codesniffer": "^3.7"
20+
"squizlabs/php_codesniffer": "^3.7",
21+
"phpunit/phpunit": "^9.6",
22+
"phpmd/phpmd": "^2.15",
23+
"phpstan/phpstan": "^1.10",
24+
"phploc/phploc": "^7.0",
25+
"php-parallel-lint/php-parallel-lint": "^1.3"
2126
}
2227
}

0 commit comments

Comments
 (0)