Skip to content

Commit

Permalink
Merge pull request #10 from dotkernel/issue-8
Browse files Browse the repository at this point in the history
Issue #8: Code quality
  • Loading branch information
alexmerlin committed Jul 12, 2023
2 parents 87258d0 + 925b0c9 commit 5919f2a
Show file tree
Hide file tree
Showing 29 changed files with 1,442 additions and 166 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/cs-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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 update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run phpcs checks
run: vendor/bin/phpcs
46 changes: 46 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
on:
- push

name: Run static analysis

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 update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run static analysis
run: vendor/bin/psalm --no-cache --output-format=github --show-info=false --threads=4
47 changes: 47 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
on:
- push

name: Run PHPUnit tests

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 PHPUnit tests
run: vendor/bin/phpunit --colors=always
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
clover.xml
coveralls-upload.json
phpunit.xml
.phpcs-cache
.phpunit.result.cache

# Created by .ignore support plugin (hsz.mobi)
### JetBrains template
Expand Down
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
DotKernel's debug bar built on top of [maximebf/php-debugbar](https://github.com/maximebf/php-debugbar).

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

[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-debugbar)](https://github.com/dotkernel/dot-debugbar/issues)
[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-debugbar)](https://github.com/dotkernel/dot-debugbar/network)
[![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-debugbar)](https://github.com/dotkernel/dot-debugbar/stargazers)
[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-debugbar)](https://github.com/dotkernel/dot-debugbar/blob/main/LICENSE.md)
[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-debugbar)](https://github.com/dotkernel/dot-debugbar/blob/1.0/LICENSE.md)

![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-debugbar/1.0.x-dev)
[![Build Static](https://github.com/dotkernel/dot-debugbar/actions/workflows/static-analysis.yml/badge.svg?branch=1.0)](https://github.com/dotkernel/dot-debugbar/actions/workflows/static-analysis.yml)

[![SymfonyInsight](https://insight.symfony.com/projects/c1dc83af-a4b3-4a46-a80c-d87dff782089/big.svg)](https://insight.symfony.com/projects/c1dc83af-a4b3-4a46-a80c-d87dff782089)


## Install
Install dot-debugbar in your application by running the following command:
```bash
$ composer require dotkernel/dot-debugbar
```

composer require dotkernel/dot-debugbar


## Setup
Expand All @@ -27,7 +29,7 @@ Once installed, the following components need to be registered by adding:

Locate the library's assets directory, called `assets` and copy **its contents** to your application under `public/debugbar` directory.

Locate the library's config file `config/debugbar.local.php.dist` and clone it inside your application as:
Locate the library's config file `config/debugbar.local.php` and clone it inside your application as:
* `config/autoload/debugbar.local.php.dist`
* `config/autoload/debugbar.local.php`

Expand Down Expand Up @@ -56,9 +58,9 @@ This feature can be useful if you need to add custom logic for when dot-debugbar
Other than the data being automatically collected during a session, dot-debugbar can also be used to log messages, measure durations, debug database queries and more...

When you need an instance of DebugBar, locate an instance of it in your application's container using:
```php
$debugBar = $container->get(\Dot\DebugBar\DebugBar::class);
```

$debugBar = $container->get(\Dot\DebugBar\DebugBar::class);

then your factory can inject `$debugBar` as a dependency in your class.

OR
Expand Down
28 changes: 26 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,42 @@
}
],
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"autoload": {
"psr-4": {
"Dot\\DebugBar\\": "src/"
}
},
"require": {
"php": "~7.4.0||~8.0.0||~8.1.0",
"php": "~8.1.0 || ~8.2.0",
"doctrine/orm": "^2.7",
"dotkernel/dot-twigrenderer": "^3.1",
"laminas/laminas-stratigility": "^3.9",
"maximebf/debugbar": "^1.17"
},
"autoload-dev": {
"psr-4": {
"DotTest\\DebugBar\\": "test/"
}
},
"require-dev": {
"laminas/laminas-coding-standard": "^2.5",
"phpunit/phpunit": "^10.2",
"vimeo/psalm": "^5.13"
},
"scripts": {
"check": [
"@cs-check",
"@test"
],
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"test": "phpunit --colors=always",
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
"static-analysis": "psalm --shepherd --stats"
}
}
6 changes: 3 additions & 3 deletions config/debugbar.local.php.dist → config/debugbar.local.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
* @see \DebugBar\JavascriptRenderer::setOptions()
*/
'javascript_renderer' => [
'base_url' => '',
'base_path' => '',
'disable_jquery' => false,
'base_url' => '',
'base_path' => '',
'disable_jquery' => false,
'disable_fontawesome' => false,
'disable_highlightjs' => false,
],
Expand Down
21 changes: 21 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

<arg name="basepath" value="."/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="80"/>

<!-- Show progress -->
<arg value="p"/>

<!-- Paths to check -->
<file>config</file>
<file>src</file>
<file>test</file>

<!-- Include all rules from the Laminas Coding Standard -->
<rule ref="LaminasCodingStandard"/>
</ruleset>
17 changes: 17 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd"
bootstrap="./vendor/autoload.php"
colors="true">
<testsuites>
<testsuite name="Dot-DebugBar Test Suite">
<directory>./test</directory>
</testsuite>
</testsuites>
<coverage/>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
16 changes: 16 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.13.1@086b94371304750d1c673315321a55d15fc59015">
<file src="src/Extension/DebugBarExtension.php">
<UndefinedInterfaceMethod>
<code>getJavascriptRenderer</code>
<code>getJavascriptRenderer</code>
<code>getJavascriptRenderer</code>
</UndefinedInterfaceMethod>
</file>
<file src="src/Factory/DebugBarMiddlewareFactory.php">
<UndefinedClass>
<code>ErrorResponseGenerator</code>
<code>ErrorResponseGenerator</code>
</UndefinedClass>
</file>
</files>
18 changes: 18 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
resolveFromConfigFile="true"
findUnusedCode="false"
findUnusedBaselineEntry="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
errorBaseline="psalm-baseline.xml"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
17 changes: 9 additions & 8 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace Dot\DebugBar;

Expand All @@ -19,7 +19,7 @@ class ConfigProvider
public function __invoke(): array
{
return [
'dependencies' => $this->getDependencyConfig()
'dependencies' => $this->getDependencyConfig(),
];
}

Expand All @@ -29,14 +29,15 @@ public function __invoke(): array
public function getDependencyConfig(): array
{
return [
'aliases' => [
DebugBarMiddlewareInterface::class => DebugBarMiddleware::class
'aliases' => [
DebugBarInterface::class => DebugBar::class,
DebugBarMiddlewareInterface::class => DebugBarMiddleware::class,
],
'factories' => [
DebugBar::class => DebugBarFactory::class,
DebugBarExtension::class => DebugBarExtensionFactory::class,
DebugBarMiddleware::class => DebugBarMiddlewareFactory::class
]
DebugBar::class => DebugBarFactory::class,
DebugBarExtension::class => DebugBarExtensionFactory::class,
DebugBarMiddleware::class => DebugBarMiddlewareFactory::class,
],
];
}
}
Loading

0 comments on commit 5919f2a

Please sign in to comment.