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

PHP7.1, coding style #4

Merged
merged 1 commit into from Jun 20, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 7 additions & 13 deletions .editorconfig
@@ -1,26 +1,20 @@
# EditorConfig is awesome: http://EditorConfig.org

# Top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true

# JS / PHP
[*.{js,php,phpt}]
charset = utf-8
trim_trailing_whitespace = true
indent_style = tab
indent_size = 4
indent_size = tab
tab_width = 4

# NEON
[*.neon]
charset = utf-8
indent_style = tab
[*.md]
indent_style = space
indent_size = 4

# Composer, NPM, Travis, BitbucketPipelines
[{composer.json,package.json,.travis.yml,bitbucket-pipelines.yml}]
[{composer.json,package.json,.travis.yml}]
indent_style = space
indent_size = 2
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -6,6 +6,8 @@
/composer.lock

# Tests
/temp/
/tests/*.log
/tests/tmp
/tests/coverage.html
/coverage.xml
24 changes: 11 additions & 13 deletions .travis.yml
@@ -1,9 +1,8 @@
language: php

php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.1
- 7.2

before_install:
# turn off XDebug
Expand All @@ -19,42 +18,41 @@ script:

jobs:
include:
- env: title="Lowest Dependencies 5.6"
php: 5.6
- env: title="Lowest Dependencies 7.1"
php: 7.1
install:
- travis_retry composer update --no-progress --prefer-dist --prefer-lowest
script:
- composer run-script tester

- env: title="Lowest Dependencies 7.1"
php: 7.1
- env: title="Lowest Dependencies 7.2"
php: 7.2
install:
- travis_retry composer update --no-progress --prefer-dist --prefer-lowest
script:
- composer run-script tester

- stage: Quality Assurance
php: 7.1
php: 7.2
script:
- composer run-script qa

- stage: Test Coverage
php: 7.1
php: 7.2
script:
- composer run-script coverage
after_script:
- wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar
- wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.0.0/php-coveralls.phar
- php coveralls.phar --verbose --config tests/.coveralls.yml

- stage: Phpstan
php: 7.1
php: 7.2
script:
- composer run-script phpstan-install
- composer run-script phpstan

allow_failures:
- stage: Test Coverage
- stage: Phpstan

after_failure:
# Print *.actual content
Expand Down
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -26,6 +26,8 @@ composer require contributte/tracy

| State | Version | Branch | PHP |
|-------------|---------|----------|----------|
| dev | `^0.3` | `master` | `>= 7.1` |
| stable | `^0.2` | `master` | `>= 7.1` |
| stable | `^0.1` | `master` | `>= 5.6` |

## Overview
Expand All @@ -44,6 +46,13 @@ composer require contributte/tracy
</br>
<a href="https://github.com/f3l1x">Milan Felix Šulc</a>
</td>
<td align="center">
<a href="https://github.com/mabar">
<img width="150" height="150" src="https://avatars0.githubusercontent.com/u/20974277?s=400&v=4">
</a>
</br>
<a href="https://github.com/mabar">Marek Bartoš</a>
</td>
</tr>
<tbody>
</table>
Expand Down
28 changes: 19 additions & 9 deletions composer.json
@@ -1,9 +1,17 @@
{
"name": "contributte/tracy",
"description": "Tuned Tracy Bars/Panels/BlueScreens for easy-developing",
"keywords": ["nette", "tracy", "profile", "bluescreen", "develop"],
"keywords": [
"nette",
"tracy",
"profile",
"bluescreen",
"develop"
],
"type": "library",
"license": "MIT",
"license": [
"MIT"
],
"homepage": "https://github.com/contributte/tracy",
"authors": [
{
Expand All @@ -12,16 +20,17 @@
}
],
"require": {
"php": ">= 5.6",
"php": ">= 7.1",
"tracy/tracy": "~2.4.15 || ~2.5.0"
},
"require-dev": {
"ninjify/qa": "^0.4.0",
"ninjify/qa": "^0.8.0",
"ninjify/nunjuck": "^0.2.0",
"nette/di": "~2.4.12"
},
"conflict": {
"nette/di": "<2.4.12"
"nette/di": "<2.4.12",
"nette/utils": "<2.5.2"
},
"autoload": {
"psr-4": {
Expand All @@ -41,18 +50,19 @@
],
"phpstan-install": [
"mkdir -p temp/phpstan",
"composer require -d temp/phpstan phpstan/phpstan:0.8.5",
"composer require -d temp/phpstan phpstan/phpstan-nette:0.8.3"
"composer require -d temp/phpstan phpstan/phpstan:0.9.2",
"composer require -d temp/phpstan phpstan/phpstan-nette:0.9",
"composer require -d temp/phpstan phpstan/phpstan-strict-rules:0.9"
],
"phpstan": [
"temp/phpstan/vendor/bin/phpstan analyse -l 1 -c phpstan.neon src"
"temp/phpstan/vendor/bin/phpstan analyse -l max -c phpstan.neon src"
]
},
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"branch-alias": {
"dev-master": "0.2.x-dev"
"dev-master": "0.3.x-dev"
}
}
}
3 changes: 1 addition & 2 deletions phpstan.neon
@@ -1,5 +1,4 @@
includes:
- temp/phpstan/vendor/phpstan/phpstan-strict-rules/rules.neon
- temp/phpstan/vendor/phpstan/phpstan-nette/extension.neon
- temp/phpstan/vendor/phpstan/phpstan-nette/rules.neon

parameters:
10 changes: 3 additions & 7 deletions ruleset.xml
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="Contributte">
<!-- Extending ruleset -->
<rule ref="vendor/ninjify/coding-standard/ruleset.xml"/>
<!-- Contributte Coding Standard -->
<rule ref="./vendor/ninjify/coding-standard/contributte.xml"/>

<!-- Project rules -->
<!-- Specific rules -->
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
<properties>
<property name="rootNamespaces" type="array" value="
Expand All @@ -13,10 +13,6 @@
</properties>
</rule>

<rule ref="SlevomatCodingStandard.ControlStructures.AssignmentInCondition">
<exclude name="SlevomatCodingStandard.ControlStructures.AssignmentInCondition.assignmentInCondition"/>
</rule>

<!-- Exclude folders -->
<exclude-pattern>/tests/tmp</exclude-pattern>
</ruleset>
24 changes: 10 additions & 14 deletions src/BlueScreen/ContainerBuilderDefinitionsBlueScreen.php
@@ -1,10 +1,10 @@
<?php
<?php declare(strict_types = 1);

namespace Contributte\Tracy\BlueScreen;

use Exception;
use Nette\DI\ContainerBuilder;
use Nette\DI\ServiceCreationException;
use Throwable;
use Tracy\Dumper;
use Tracy\Helpers;

Expand All @@ -14,39 +14,35 @@ class ContainerBuilderDefinitionsBlueScreen
/** @var ContainerBuilder */
private $builder;

/**
* @param ContainerBuilder $builder
*/
public function __construct(ContainerBuilder $builder)
{
$this->builder = $builder;
}

/**
* @param Exception $e
* @return array|null
* @return string[]|null
*/
public function __invoke($e)
public function __invoke(?Throwable $e): ?array
{
if (!$e) return NULL;
if (!($e instanceof ServiceCreationException)) return NULL;
if (!($trace = Helpers::findTrace($e->getTrace(), 'Nette\DI\Compiler::compile'))) return NULL;
if ($e === null) return null;
if (!($e instanceof ServiceCreationException)) return null;
if (!($trace = Helpers::findTrace($e->getTrace(), 'Nette\DI\Compiler::compile'))) return null;

$parts = [];

// Single definition
preg_match("#Class .+ used in service '([a-zA-Z0-9_]+)' not found.#", $e->getMessage(), $matches);
if ($matches) {
list ($all, $serviceName) = $matches;
[$all, $serviceName] = $matches;
$parts[] = sprintf(
"<div><h3>Definition for '%s'</h3>%s</div>",
$serviceName,
Dumper::toHtml($this->builder->getDefinition($serviceName), [Dumper::LIVE => TRUE, Dumper::COLLAPSE => FALSE])
Dumper::toHtml($this->builder->getDefinition($serviceName), [Dumper::LIVE => true, Dumper::COLLAPSE => false])
);
}

// All definitions
$parts[] = sprintf('<div><h3>All definitions</h3>%s</div>', Dumper::toHtml($this->builder->getDefinitions(), [Dumper::LIVE => TRUE, Dumper::COLLAPSE => FALSE]));
$parts[] = sprintf('<div><h3>All definitions</h3>%s</div>', Dumper::toHtml($this->builder->getDefinitions(), [Dumper::LIVE => true, Dumper::COLLAPSE => false]));

return [
'tab' => 'ContainerBuilder - definitions',
Expand Down
20 changes: 8 additions & 12 deletions src/BlueScreen/ContainerBuilderParametersBlueScreen.php
@@ -1,10 +1,10 @@
<?php
<?php declare(strict_types = 1);

namespace Contributte\Tracy\BlueScreen;

use Exception;
use Nette\DI\ContainerBuilder;
use Nette\InvalidArgumentException;
use Throwable;
use Tracy\Dumper;
use Tracy\Helpers;

Expand All @@ -14,27 +14,23 @@ class ContainerBuilderParametersBlueScreen
/** @var ContainerBuilder */
private $builder;

/**
* @param ContainerBuilder $builder
*/
public function __construct(ContainerBuilder $builder)
{
$this->builder = $builder;
}

/**
* @param Exception $e
* @return array|null
* @return string[]|null
*/
public function __invoke($e)
public function __invoke(?Throwable $e): ?array
{
if (!$e) return NULL;
if (!($e instanceof InvalidArgumentException)) return NULL;
if (!($trace = Helpers::findTrace($e->getTrace(), 'Nette\DI\Compiler::compile'))) return NULL;
if ($e === null) return null;
if (!($e instanceof InvalidArgumentException)) return null;
if (!($trace = Helpers::findTrace($e->getTrace(), 'Nette\DI\Compiler::compile'))) return null;

return [
'tab' => 'ContainerBuilder - parameters',
'panel' => Dumper::toHtml($this->builder->parameters, [Dumper::LIVE => TRUE, Dumper::COLLAPSE => FALSE]),
'panel' => Dumper::toHtml($this->builder->parameters, [Dumper::LIVE => true, Dumper::COLLAPSE => false]),
];
}

Expand Down
14 changes: 2 additions & 12 deletions src/DI/TracyBlueScreensExtension.php
@@ -1,29 +1,19 @@
<?php
<?php declare(strict_types = 1);

namespace Contributte\Tracy\DI;

use Contributte\Tracy\BlueScreen\ContainerBuilderDefinitionsBlueScreen;
use Contributte\Tracy\BlueScreen\ContainerBuilderParametersBlueScreen;
use Nette\DI\CompilerExtension;
use Nette\InvalidStateException;
use Tracy\Debugger;

final class TracyBlueScreensExtension extends CompilerExtension
{

/**
* Register services
*
* @return void
*/
public function loadConfiguration()
public function loadConfiguration(): void
{
$builder = $this->getContainerBuilder();

if (!class_exists(Debugger::class)) {
throw new InvalidStateException('Tracy is required, please install her.');
}

Debugger::getBlueScreen()->addPanel(new ContainerBuilderParametersBlueScreen($builder));
Debugger::getBlueScreen()->addPanel(new ContainerBuilderDefinitionsBlueScreen($builder));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

use Ninjify\Nunjuck\Environment;

Expand Down