Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code quality related changes. #197

Merged
merged 5 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
on:
- push

name: Run Codecov checks

jobs:
code-coverage:
name: Code Coverage

runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- ubuntu-latest

php:
- "8.1"
- "8.2"

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
coverage: pcov
ini-values: assert.exception=1, zend.assertions=1, error_reporting=-1, log_errors_max_len=0, display_errors=On
tools: composer:v2, cs2pr

- name: Determine composer cache directory
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v3
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php }}-composer-

- name: Install dependencies with composer
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Setup project
run: |
mv config/autoload/local.php.dist config/autoload/local.php
mv config/autoload/mail.local.php.dist config/autoload/mail.local.php
mv config/autoload/local.test.php.dist config/autoload/local.test.php

- name: Collect code coverage with PHPUnit
run: vendor/bin/phpunit --colors=always --coverage-clover clover.xml

- name: Send code coverage report to Codecov.io
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
47 changes: 47 additions & 0 deletions .github/workflows/cs-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
on:
- push

name: Run phpcs checks

jobs:
mutation:
name: PHP ${{ matrix.php }}-${{ matrix.os }}

runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- ubuntu-latest

php:
- "8.1"
- "8.2"

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
tools: composer:v2, cs2pr
coverage: none

- name: Determine composer cache directory
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v3
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php }}-composer-

- name: Install dependencies with composer
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run phpcs checks
run: vendor/bin/phpcs
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
on:
# - pull_request
- push

name: Run PHPUnit tests
Expand All @@ -17,6 +16,7 @@ jobs:

php:
- "8.1"
- "8.2"

steps:
- name: Checkout
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
on:
# - pull_request
- push

name: static analysis
name: Run static analysis

jobs:
mutation:
Expand All @@ -17,6 +16,7 @@ jobs:

php:
- "8.1"
- "8.2"

steps:
- name: Checkout
Expand All @@ -39,8 +39,9 @@ jobs:
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php }}-composer-

- name: Install dependencies with composer
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Static analysis
run: vendor/bin/psalm --output-format=github --show-info=false --threads=4 --php-version="${{ matrix.php }}"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ composer.phar
composer.lock

.phpunit.result.cache
.phpcs-cache
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
Based on Enrico Zimuel's [Zend Expressive API - Skeleton example](https://github.com/ezimuel/zend-expressive-api), DotKernel API runs on [Laminas](https://github.com/laminas) and [Mezzio](https://github.com/mezzio) components and implements standards like PSR-3, PSR-4, PSR-7, PSR-11 and PSR-15.

![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/api)
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/api/4.2.0)

[![GitHub issues](https://img.shields.io/github/issues/dotkernel/api)](https://github.com/dotkernel/api/issues)
[![GitHub forks](https://img.shields.io/github/forks/dotkernel/api)](https://github.com/dotkernel/api/network)
[![GitHub stars](https://img.shields.io/github/stars/dotkernel/api)](https://github.com/dotkernel/api/stargazers)
[![GitHub license](https://img.shields.io/github/license/dotkernel/api)](https://github.com/dotkernel/api/blob/4.0/LICENSE.md)

![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/api/4.0.x-dev)

[![Build Static](https://github.com/dotkernel/api/actions/workflows/static-analysis.yml/badge.svg?branch=4.0)](https://github.com/dotkernel/api/actions/workflows/static-analysis.yml)
[![Build Static](https://github.com/dotkernel/api/actions/workflows/run-tests.yml/badge.svg?branch=4.0)](https://github.com/dotkernel/api/actions/workflows/run-tests.yml)
[![codecov](https://codecov.io/gh/dotkernel/api/graph/badge.svg?token=53FN78G5CK)](https://codecov.io/gh/dotkernel/api)

[![SymfonyInsight](https://insight.symfony.com/projects/7f9143cc-5e3c-4cfc-992c-377a001fde3e/big.svg)](https://insight.symfony.com/projects/7f9143cc-5e3c-4cfc-992c-377a001fde3e)

Expand Down Expand Up @@ -65,9 +65,6 @@ composer development-status
* duplicate `config/autoload/local.php.dist` as `config/autoload/local.php`
* duplicate `config/autoload/mail.local.php.dist` as `config/autoload/mail.local.php` <- if your API will send emails, make sure you fill in SMTP connection params

Optional:
* duplicate `phpcs.xml.dist` as `phpcs.xml`


### Step 5: Setup database

Expand Down
5 changes: 1 addition & 4 deletions bin/clear-config-cache.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<?php

/**
* Script for clearing the configuration cache.
*
* Can also be invoked as `composer clear-config-cache`.
*
* @see https://github.com/mezzio/mezzio-skeleton for the canonical source repository
* @copyright Copyright (c) 2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/mezzio/mezzio-skeleton/blob/master/LICENSE.md New BSD License
*/

declare(strict_types=1);
Expand Down
33 changes: 19 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,14 @@
"php": "~8.1.0 || ~8.2.0",
"ext-gd": "*",
"ext-json": "*",
"brick/math": "^0.10.0",
"dotkernel/dot-annotated-services": "^4.0.0",
"dotkernel/dot-cli": "^3.2.0",
"dotkernel/dot-data-fixtures": "^1.0",
"dotkernel/dot-doctrine-metadata": "^3.1.0",
"dotkernel/dot-errorhandler": "^3.2.0",
"dotkernel/dot-mail": "~3.4 || ~4.0",
"dotkernel/dot-response-header": "^3.1.0",
"laminas/laminas-component-installer": "^2.8.0",
"dotkernel/dot-annotated-services": "^4.1.2",
"dotkernel/dot-cli": "^3.4.0",
"dotkernel/dot-data-fixtures": "^1.1.1",
"dotkernel/dot-doctrine-metadata": "^3.2.0",
"dotkernel/dot-errorhandler": "^3.3.1",
"dotkernel/dot-mail": "~4.1.0",
"dotkernel/dot-response-header": "^3.2.0",
"laminas/laminas-component-installer": "^3.3.0",
"laminas/laminas-config": "^3.7.0",
"laminas/laminas-config-aggregator": "^1.7.0",
"laminas/laminas-http": "^2.15.1",
Expand All @@ -75,20 +74,25 @@
"symfony/filesystem": "^6.2"
},
"require-dev": {
"laminas/laminas-coding-standard": "^2.3",
"laminas/laminas-coding-standard": "^2.5",
"laminas/laminas-development-mode": "^3.6",
"mezzio/mezzio-tooling": "^2.5",
"phpunit/phpunit": "^9.5",
"phpunit/phpunit": "^10.2",
"roave/security-advisories": "dev-latest",
"vimeo/psalm": "^4.27"
"vimeo/psalm": "^5.13"
},
"autoload": {
"psr-4": {
"Api\\Admin\\": "src/Admin/src/",
"Api\\App\\": "src/App/src/",
"Api\\User\\": "src/User/src/",
"Api\\Fixtures\\": "data/doctrine/fixtures/",
"AppTest\\Functional\\": "tests/AppTest/Functional/src/"
"Api\\Fixtures\\": "data/doctrine/fixtures/"
}
},
"autoload-dev": {
"psr-4": {
"ApiTest\\Functional\\": "test/Functional/",
"ApiTest\\Unit\\": "test/Unit/"
}
},
"scripts": {
Expand All @@ -109,6 +113,7 @@
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"serve": "php -S 0.0.0.0:8080 -t public/",
"static-analysis": "psalm --shepherd --stats",
"test": "phpunit --colors=always",
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml"
}
Expand Down
22 changes: 13 additions & 9 deletions config/autoload/authorization.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

declare(strict_types=1);

use Api\User\Entity\UserRole;
use Api\Admin\Entity\AdminRole;
use Api\User\Entity\UserRole;

return [
/**
Expand All @@ -18,14 +18,18 @@
* C has B as a parent. That means B inherits the permissions of C, and A inherits the permissions of C.
*/
'mezzio-authorization-rbac' => [
'roles' => [
'roles' => [
AdminRole::ROLE_SUPERUSER => [],
AdminRole::ROLE_ADMIN => [AdminRole::ROLE_SUPERUSER],
UserRole::ROLE_GUEST => [UserRole::ROLE_USER]
AdminRole::ROLE_ADMIN => [
AdminRole::ROLE_SUPERUSER,
],
UserRole::ROLE_GUEST => [
UserRole::ROLE_USER,
],
],
'permissions' => [
AdminRole::ROLE_SUPERUSER => [],
AdminRole::ROLE_ADMIN => [
AdminRole::ROLE_ADMIN => [
'admin.my-account.update',
'admin.my-account.view',
'admin.create',
Expand All @@ -49,15 +53,15 @@
'error.report',
'home',
],
UserRole::ROLE_USER => [
UserRole::ROLE_USER => [
'user.my-account.delete',
'user.my-account.update',
'user.my-account.view',
'user.my-avatar.create',
'user.my-avatar.delete',
'user.my-avatar.view',
],
UserRole::ROLE_GUEST => [
UserRole::ROLE_GUEST => [
'account.activate.request',
'account.activate',
'account.register',
Expand All @@ -70,7 +74,7 @@
'error.report',
'home',
'user.create',
]
],
],
]
],
];
16 changes: 8 additions & 8 deletions config/autoload/cli.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
use Dot\Cli\FileLockerInterface;

return [
'dot_cli' => [
'version' => '1.0.0',
'name' => 'DotKernel CLI',
'dot_cli' => [
'version' => '1.0.0',
'name' => 'DotKernel CLI',
'commands' => [
DemoCommand::getDefaultName() => DemoCommand::class,
RouteListCommand::getDefaultName() => RouteListCommand::class,
AdminCreateCommand::getDefaultName() => AdminCreateCommand::class,
DemoCommand::getDefaultName() => DemoCommand::class,
RouteListCommand::getDefaultName() => RouteListCommand::class,
AdminCreateCommand::getDefaultName() => AdminCreateCommand::class,
TokenGenerateCommand::getDefaultName() => TokenGenerateCommand::class,
]
],
],
FileLockerInterface::class => [
'enabled' => true,
'dirPath' => getcwd() . '/data/lock',
]
],
];
14 changes: 9 additions & 5 deletions config/autoload/cors.local.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ use Mezzio\Cors\Configuration\ConfigurationInterface;

return [
ConfigurationInterface::CONFIGURATION_IDENTIFIER => [
'allowed_origins' => [
'allowed_origins' => [
/**
* Leaving this line here makes your application accessible by any origin.
*
* To restrict, replace this line with a list of origins that should have access to your application.
* Example: "domain1.com", "domain2.com"
*/
ConfigurationInterface::ANY_ORIGIN
ConfigurationInterface::ANY_ORIGIN,
],
'allowed_headers' => ['Accept', 'Content-Type', 'Authorization'], // Custom headers
'allowed_max_age' => '600', // 10 minutes
'allowed_headers' => [
'Accept',
'Content-Type',
'Authorization',
], // Custom headers
'allowed_max_age' => '600', // 10 minutes
'credentials_allowed' => true, // Allow cookies
'exposed_headers' => [], // Tell client that the API will always return this header
'exposed_headers' => [], // Tell client that the API will always return this header
],
];
Loading