Skip to content

Commit 7e2df98

Browse files
committed
CI, tests like in other ma-core packages, fixed PHPStan errors
1 parent 6c5e0e8 commit 7e2df98

File tree

13 files changed

+341
-45
lines changed

13 files changed

+341
-45
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
9+
[{*.php, *.json, *.neon}]
10+
indent_style = tab
11+
indent_size = 4
12+
13+
[*.yml]
14+
indent_style = space
15+
indent_size = 2

.github/workflows/main.yml

Lines changed: 59 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,67 @@
11
name: Integrity check
22

3-
on: [push]
3+
on:
4+
pull_request:
5+
push:
46

57
jobs:
8+
code_style:
9+
runs-on: ubuntu-latest
10+
name: Code style check
11+
steps:
12+
- name: Git clone
13+
uses: actions/checkout@master
14+
15+
- name: Install PHP
16+
uses: shivammathur/setup-php@master
17+
with:
18+
php-version: 7.4
19+
coverage: pcov
20+
21+
- name: Install composer dependencies
22+
run: |
23+
composer run cs:install
24+
25+
# Install app dependencies
26+
composer install --no-interaction --prefer-dist
27+
28+
# Check code checker and coding standards
29+
- name: Check coding standards
30+
run: |
31+
composer run cs:check
32+
33+
- name: Check PHPStan rules
34+
run: composer run phpstan
35+
636
build:
737
runs-on: ubuntu-latest
38+
strategy:
39+
matrix:
40+
php: ['7.2', '7.3', '7.4'] # 8.0
841

42+
name: PHP ${{ matrix.php }} tests
943
steps:
10-
- uses: actions/checkout@master
11-
12-
- name: Install PHP
13-
uses: shivammathur/setup-php@master
14-
with:
15-
php-version: 7.4
16-
17-
- name: Install composer deps
18-
run: |
19-
composer create-project nette/code-checker temp/code-checker ^3 --no-progress
20-
composer create-project nette/coding-standard temp/coding-standard ^2 --no-progress
21-
22-
# Install app deps
23-
composer install --no-interaction --prefer-dist
24-
25-
# Check code checker and coding standards
26-
- name: Check coding standards
27-
run: |
28-
php temp/code-checker/code-checker --short-arrays --strict-types --fix --no-progress
29-
php temp/coding-standard/ecs check src --config temp/coding-standard/coding-standard-php71.yml
30-
31-
- name: Check PHPStan rules
32-
run: composer phpstan
44+
- name: Git clone
45+
uses: actions/checkout@master
46+
47+
- name: Install PHP
48+
uses: shivammathur/setup-php@master
49+
with:
50+
php-version: ${{ matrix.php }}
51+
coverage: pcov
52+
53+
- name: Install composer dependencies
54+
run: |
55+
composer install --no-interaction --prefer-dist
56+
57+
- name: Run tests
58+
run: composer run test
59+
60+
- name: Upload coverage to Codecov
61+
uses: codecov/codecov-action@v1
62+
with:
63+
token: ${{ secrets.CODECOV_TOKEN }}
64+
file: ./coverage.xml
65+
flags: unittests
66+
name: codecov-umbrella
67+
fail_ci_if_error: true

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# IDEs
2+
.idea/
3+
.vscode/
4+
5+
# App
6+
log/
7+
temp/
8+
vendor/
9+
composer.lock
10+
11+
# Tests
12+
coverage.xml

CODE_OF_CONDUCT.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex characteristics, gender identity and expression,
9+
level of experience, education, socio-economic status, nationality, personal
10+
appearance, race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at [email protected]. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org
74+
75+
For answers to common questions about this code of conduct, see
76+
https://www.contributor-covenant.org/faq

README.md

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,43 @@
1-
Mandelbrot set simple PHP Generator
2-
===================================
1+
# Mandelbrot set simple PHP Generator
2+
3+
[![Integrity check](https://github.com/mathematicator-core/mandelbrot-set/workflows/Integrity%20check/badge.svg)](https://github.com/mathematicator-core/mandelbrot-set/actions?query=workflow%3A%22Integrity+check%22)
4+
[![codecov](https://codecov.io/gh/mathematicator-core/mandelbrot-set/branch/master/graph/badge.svg)](https://codecov.io/gh/mathematicator-core/mandelbrot-set)
5+
[![License: MIT](https://img.shields.io/badge/License-MIT-brightgreen.svg)](./LICENSE)
36

4-
![Integrity check](https://github.com/mathematicator-core/mandelbrot-set/workflows/Integrity%20check/badge.svg)
57

68
Simple Generator for create image of Mandelbrot set as base64 by full-configuration request.
79

810
This package was inspired by Pavol Hejný.
911

1012
![Mandelbrot set render](mandelbrot-set.png)
1113

12-
Install
13-
-------
14+
## Installation
1415

15-
By Composer:
16+
Via Composer:
1617

1718
```shell
1819
composer require mathematicator-core/mandelbrot-set
1920
```
2021

21-
Use
22-
---
22+
## Usage
2323

2424
Inject `MandelbrotSet` service to your application, create new Request and process by `loadImage()` method.
25+
26+
## Contribution
27+
28+
### Tests
29+
30+
All new contributions should have its unit tests in `/tests` directory.
31+
32+
Before you send a PR, please, check all tests pass.
33+
34+
This package uses [Nette Tester](https://tester.nette.org/). You can run tests via command:
35+
```bash
36+
composer test
37+
````
38+
39+
Before PR, please run complete code check via command:
40+
```bash
41+
composer cs:install # only first time
42+
composer fix # otherwise pre-commit hook can fail
43+
````

composer.json

Lines changed: 62 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
{
22
"name": "mathematicator-core/mandelbrot-set",
33
"description": "Mandelbrot set simple PHP Generator.",
4+
"keywords": [
5+
"mathematicator",
6+
"math",
7+
"php",
8+
"mandelbrot"
9+
],
10+
"type": "library",
11+
"license": "MIT",
412
"homepage": "https://github.com/mathematicator-core/mandelbrot-set",
513
"authors": [
614
{
@@ -13,24 +21,67 @@
1321
}
1422
],
1523
"require": {
16-
"php": ">=7.1",
24+
"php": ">=7.2",
1725
"nette/utils": "^3.0",
18-
"mathematicator-core/vizualizator": "^1.0"
26+
"mathematicator-core/vizualizator": "^2.0@dev"
1927
},
2028
"require-dev": {
29+
"brainmaestro/composer-git-hooks": "dev-master",
30+
"nette/bootstrap": "^3.0",
31+
"nette/tester": "^2.3",
2132
"phpstan/phpstan": "^0.12.18",
22-
"tracy/tracy": "^2.7",
2333
"phpstan/phpstan-nette": "^0.12.6"
2434
},
2535
"autoload": {
26-
"classmap": [
27-
"src/"
28-
]
36+
"psr-4": {
37+
"Mathematicator\\MandelbrotSet\\": "src/"
38+
}
39+
},
40+
"autoload-dev": {
41+
"psr-4": {
42+
"Mathematicator\\MandelbrotSet\\Tests\\": "tests/MandelbrotSetTests/"
43+
}
2944
},
3045
"scripts": {
31-
"phpstan": [
32-
"vendor/bin/phpstan analyse src -c phpstan.neon --level 6 --no-progress"
33-
]
46+
"post-install-cmd": "cghooks add --ignore-lock",
47+
"post-update-cmd": "cghooks update",
48+
"cs:install": [
49+
"composer create-project nette/code-checker temp/code-checker ^3 --no-progress",
50+
"composer create-project nette/coding-standard temp/coding-standard ^2 --no-progress"
51+
],
52+
"cs:check": [
53+
"php temp/code-checker/code-checker --short-arrays --strict-types --no-progress",
54+
"php temp/coding-standard/ecs check src --config temp/coding-standard/coding-standard-php71.yml"
55+
],
56+
"cs:fix": [
57+
"php temp/code-checker/code-checker --short-arrays --strict-types --fix --no-progress",
58+
"php temp/coding-standard/ecs check src --config temp/coding-standard/coding-standard-php71.yml --fix"
59+
],
60+
"phpstan": "vendor/bin/phpstan analyse src -c phpstan.neon --level 8 --no-progress",
61+
"fix": [
62+
"composer update",
63+
"composer cs:fix",
64+
"composer phpstan",
65+
"composer test"
66+
],
67+
"test": "vendor/bin/tester -s -c tests/php.ini -p php tests --coverage coverage.xml --coverage-src src",
68+
"cghooks": "vendor/bin/cghooks"
3469
},
35-
"minimum-stability": "stable"
36-
}
70+
"minimum-stability": "stable",
71+
"config": {
72+
"sort-packages": true
73+
},
74+
"extra": {
75+
"branch-alias": {
76+
"dev-master": "2.0.x-dev"
77+
},
78+
"hooks": {
79+
"post-merge": "composer install",
80+
"pre-commit": [
81+
"composer cs:check",
82+
"composer phpstan",
83+
"composer test"
84+
]
85+
}
86+
}
87+
}

src/MandelbrotSet.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Mathematicator\MandelbrotSet;
66

77

8+
use Exception;
89
use Nette\Utils\FileSystem;
910

1011
/**
@@ -41,7 +42,7 @@ public function loadImage(MandelbrotSetRequest $request): string
4142
$this->generate($request);
4243
}
4344

44-
return 'data:' . mime_content_type($path) . ';base64,' . base64_encode(file_get_contents($path));
45+
return 'data:' . mime_content_type($path) . ';base64,' . base64_encode((string) file_get_contents($path));
4546
}
4647

4748

@@ -57,6 +58,11 @@ public function generate(MandelbrotSetRequest $request): void
5758
$dim_x = $w;
5859
$dim_y = $h;
5960
$im = imagecreatetruecolor((int) $dim_x, (int) $dim_y);
61+
62+
if ($im === false) {
63+
throw new Exception('Image cannot be created.');
64+
}
65+
6066
imagealphablending($im, false);
6167
imagesavealpha($im, true);
6268

src/MandelbrotSetRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,4 @@ public function getDeltaB(): int
162162
{
163163
return $this->deltaB;
164164
}
165-
}
165+
}

tests/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/*.actual
2+
**/*.expected

0 commit comments

Comments
 (0)