Skip to content

Commit 4be5188

Browse files
Merge pull request #25 from oleksandr-gribiennikov-paysera/master
Bring library code up to php 7.4 standards
2 parents ea83971 + 5d662c3 commit 4be5188

74 files changed

Lines changed: 8444 additions & 2917 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/php-cs-fixer.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Check styling
2+
3+
on: [pull_request]
4+
5+
permissions:
6+
contents: read
7+
8+
jobs:
9+
style:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
18+
- name: Setup PHP for checking styling
19+
uses: shivammathur/setup-php@v2
20+
with:
21+
php-version: 7.4
22+
coverage: none
23+
extensions: mbstring, pdo, xml, xdebug
24+
env:
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
27+
- name: Install PHP dependencies for checking styling
28+
run: composer install --no-cache --no-interaction --no-progress --ignore-platform-reqs
29+
30+
- name: Check styling
31+
run: vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php -v --dry-run --stop-on-violation --using-cache=no --path-mode=intersection ./src ./tests

.github/workflows/phpstan.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: PHPStan
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '**.php'
7+
- 'phpstan.neon.dist'
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
phpstan:
14+
name: phpstan
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Setup PHP for PHPStan
21+
uses: shivammathur/setup-php@v2
22+
with:
23+
php-version: 7.4
24+
extensions: mbstring, pdo, xml
25+
26+
- name: Install PHPStan dependencies
27+
run: composer install --no-cache --no-interaction --no-progress --ignore-platform-reqs
28+
29+
- name: Run PHPStan
30+
run: |
31+
./vendor/bin/phpstan --error-format=github analyse src/
32+
exit_code=$?
33+
if [ $exit_code -ne 0 ]; then
34+
echo "PHPStan analysis failed with exit code $exit_code"
35+
exit $exit_code
36+
fi

.github/workflows/run-tests.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Run tests
2+
3+
on: [pull_request]
4+
5+
permissions:
6+
contents: read
7+
8+
jobs:
9+
php-tests:
10+
runs-on: ubuntu-latest
11+
12+
strategy:
13+
matrix:
14+
php: [8.3, 8.2, 8.1, 8.0, 7.4]
15+
dependency-version: [prefer-lowest, prefer-stable]
16+
os: [ubuntu-latest]
17+
18+
name: P${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Build Docker image
25+
run: docker build -t lib_webtopay_ci --build-arg PHP_VER=${{ matrix.php }} .
26+
27+
- name: Run tests in Docker container
28+
run: |
29+
docker run --rm \
30+
-u root \
31+
-v $GITHUB_WORKSPACE:/var/www \
32+
lib_webtopay_ci \
33+
/bin/bash -c "mkdir -p /var/www/vendor && composer install --no-cache --no-interaction --no-progress --ignore-platform-reqs && composer run phpunit"
34+
35+

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
/vendor
2-
composer.lock
2+
.composer
3+
.phpunit.result.cache
4+
coverage
5+
.bash_history
6+
.php-cs-fixer.cache

.php-cs-fixer.dist.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
$finder = (new PhpCsFixer\Finder())
4+
->in([
5+
__DIR__ . DIRECTORY_SEPARATOR . 'src',
6+
__DIR__ . DIRECTORY_SEPARATOR . 'tests',
7+
])
8+
;
9+
10+
return (new PhpCsFixer\Config())
11+
->setRiskyAllowed(true)
12+
->setRules([
13+
'@PSR12' => true,
14+
'@PHP82Migration' => true,
15+
'strict_param' => true,
16+
'array_syntax' => ['syntax' => 'short'],
17+
'declare_strict_types' => true,
18+
])
19+
->setFinder($finder)
20+
;

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
Version history
22
===============
3+
Version 3.0.0 - 2024-04-30
4+
5+
* increased minimal PHP version to 7.4
6+
* the code was brought up to date with the latest PHP versions and standards
7+
* removed deprecated methods
8+
* removed unused code
9+
* fixed some bugs
10+
311
Version 2.0.1 - 2023-10-19
412

513
* fixed versioning texts at changelog

Dockerfile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
ARG PHP_VER
2+
FROM php:${PHP_VER}-fpm
3+
4+
RUN groupmod -g 1000 www-data && usermod -u 1000 -g 1000 www-data
5+
6+
RUN pecl install pcov \
7+
&& docker-php-ext-enable pcov
8+
9+
ADD https://github.com/mlocati/docker-php-extension-installer/releases/download/2.1.2/install-php-extensions /usr/local/bin/
10+
11+
RUN chmod +x /usr/local/bin/install-php-extensions
12+
RUN install-php-extensions \
13+
xdebug \
14+
@composer
15+
16+
RUN echo "\n[PHP]" >> /usr/local/etc/php/conf.d/docker-fpm.ini \
17+
&& echo "error_reporting=E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED" >> /usr/local/etc/php/conf.d/docker-fpm.ini \
18+
&& echo "memory_limit=512M" >> /usr/local/etc/php/conf.d/docker-fpm.ini \
19+
&& echo "upload_max_filesize=16M" >> /usr/local/etc/php/conf.d/docker-fpm.ini \
20+
&& echo "max_post_size=16M" >> /usr/local/etc/php/conf.d/docker-fpm.ini
21+
22+
RUN echo "\n[xdebug]" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
23+
&& echo "zend_extension=xdebug.so" > /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
24+
&& echo "xdebug.mode=develop,debug,coverage" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
25+
&& echo "xdebug.client_discovery_header=\"\"" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
26+
&& echo "xdebug.client_host=\"host.docker.internal\"" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
27+
&& echo "xdebug.client_port=9000" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
28+
&& echo "xdebug.discover_client_host=On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
29+
&& echo "xdebug.output_dir = \"/var/log/nginx/xdebug.log\"" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
30+
&& echo "xdebug.remote_cookie_expire_time=3600" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
31+
&& echo "xdebug.start_with_request=On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
32+
&& echo "xdebug.max_nesting_level=512" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
33+
&& echo "xdebug.log_level=0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
34+
35+
USER 1000
36+
WORKDIR /var/www

Dockerfile_build

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM php:7.4-fpm-buster
2+
3+
RUN groupmod -g 1000 www-data && usermod -u 1000 -g 1000 www-data
4+
5+
ADD https://github.com/mlocati/docker-php-extension-installer/releases/download/2.1.2/install-php-extensions /usr/local/bin/
6+
7+
RUN chmod +x /usr/local/bin/install-php-extensions
8+
RUN install-php-extensions \
9+
xdebug \
10+
@composer
11+
12+
USER 1000
13+
WORKDIR /var/www

README.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ Example:
1717
<?php
1818

1919
require_once('WebToPay.php');
20-
21-
// Your code goes here
2220
```
2321
Alternatively, you can use files in the "src" folder.
2422
Either set-up autoloader or include file "includes.php" in "src" directory.
@@ -27,26 +25,31 @@ Example:
2725
<?php
2826

2927
require_once('libwebtopay/src/includes.php');
30-
3128
// Your code goes here
3229
```
3330
Another way to install library is using composer:
3431
```
32+
// to install the latest version
33+
"composer require webtopay/libwebtopay
34+
35+
// to install the oldest supported version (in some projects)
3536
"composer require webtopay/libwebtopay "^1.6"
37+
38+
// to install version with new interface
39+
"composer require webtopay/libwebtopay "^2.0"
3640
```
3741

38-
Testing
39-
=======
42+
And then:
43+
```php
44+
<?php
4045

41-
$ phpunit
46+
use WebToPay;
47+
```
4248

43-
Demo
44-
===============
49+
Pay attention that the ^3.0 version has the same interface as the ^2.0 but newest one is brought up to
50+
PHP 7.4 standards and code style like `strict_types`, type hints etc
4551

46-
demo_shop is a simple example how you can integrate library to your project.
47-
It also shows how to get payment methods available for your project and specific amount.
52+
Testing
53+
=======
4854

49-
Demo needs write permissions to folder /var to function properly.
50-
If you want to test demo online, also change parameters in includes/config.php file to your project's.
51-
If you are testing offline, demos will still work, but paysera.com will be unable to send callback to your site -
52-
you can login to your account and copy-and-paste the callback link in your browser in that case.
55+
$ bash runt_tests.sh

0 commit comments

Comments
 (0)