Skip to content

Commit

Permalink
Update build
Browse files Browse the repository at this point in the history
  • Loading branch information
vody105 committed Sep 9, 2019
1 parent 5f88d9f commit 2b4da34
Show file tree
Hide file tree
Showing 34 changed files with 103 additions and 128 deletions.
20 changes: 7 additions & 13 deletions .travis.yml
Expand Up @@ -13,7 +13,7 @@ install:

script:
# Tests
- composer run-script tests
- make tests

after_failure:
# Print *.actual content
Expand All @@ -26,33 +26,27 @@ jobs:
install:
- travis_retry composer update --no-progress --prefer-dist --prefer-lowest
script:
- composer run-script tests
- make tests

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

- stage: Phpstan
php: 7.2
script:
- composer run-script phpstan-install
- composer run-script phpstan
- make qa

- stage: Test Coverage
if: branch = master AND type = push
php: 7.2
script:
- composer run-script coverage
- make coverage
after_script:
- wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.1.0/php-coveralls.phar
- php php-coveralls.phar --verbose --config tests/.coveralls.yml
- composer global require php-coveralls/php-coveralls ^2.1.0
- ~/.composer/vendor/bin/php-coveralls --verbose --config tests/.coveralls.yml

- stage: Outdated Dependencies
if: branch = master AND type = cron
php: 7.2
script:
- composer outdated --direct --strict
- composer outdated --direct

allow_failures:
- stage: Test Coverage
Expand Down
27 changes: 27 additions & 0 deletions Makefile
@@ -0,0 +1,27 @@
.PHONY: qa lint cs csf phpstan tests coverage

all:
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs

vendor: composer.json composer.lock
composer install

qa: lint phpstan cs

lint: vendor
vendor/bin/linter src tests

cs: vendor
vendor/bin/codesniffer --exclude=Generic.Files.LineEndings src tests

csf: vendor
vendor/bin/codefixer src tests

phpstan: vendor
vendor/bin/phpstan analyse -l max -c phpstan.neon src

tests: vendor
vendor/bin/tester -s -p php --colors 1 -C tests

coverage: vendor
vendor/bin/tester -s -p phpdbg --colors 1 -C --coverage ./coverage.xml --coverage-src ./src tests
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -26,8 +26,8 @@ composer require contributte/logging

| State | Version | Nette | Branch | PHP |
|-------------|--------------|---------|----------|----------|
| development | `^0.5` | 3.0 | `master` | `^7.2` |
| stable | `^0.4` | 3.0 | `master` | `^7.2` |
| development | `^0.5` | 3.0 | `master` | `^7.2` |
| stable | `^0.4` | 3.0 | `master` | `^7.2` |
| stable | `^0.3` | 2.4 | `master` | `>= 7.1` |

## Overview
Expand Down
30 changes: 6 additions & 24 deletions composer.json
Expand Up @@ -17,10 +17,14 @@
},
"require-dev": {
"ext-json": "*",
"ninjify/qa": "^0.8.0",
"ninjify/qa": "^0.9.0",
"ninjify/nunjuck": "^0.2.0",
"nette/di": "^3.0.0",
"sentry/sentry": "^1.9.2"
"sentry/sentry": "^1.9.2",
"phpstan/phpstan-deprecation-rules": "^0.11",
"phpstan/phpstan-nette": "^0.11",
"phpstan/phpstan-shim": "^0.11",
"phpstan/phpstan-strict-rules": "^0.11"
},
"conflict": {
"nette/di": "<3.0"
Expand All @@ -36,28 +40,6 @@
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"qa": [
"linter src tests",
"codesniffer src tests"
],
"tests": [
"tester -s -p php --colors 1 -C tests/cases"
],
"coverage": [
"tester -s -p phpdbg --colors 1 -C --coverage ./coverage.xml --coverage-src ./src tests/cases"
],
"phpstan-install": [
"mkdir -p temp/phpstan",
"composer require -d temp/phpstan phpstan/phpstan:^0.10",
"composer require -d temp/phpstan phpstan/phpstan-deprecation-rules:^0.10",
"composer require -d temp/phpstan phpstan/phpstan-nette:^0.10",
"composer require -d temp/phpstan phpstan/phpstan-strict-rules:^0.10"
],
"phpstan": [
"temp/phpstan/vendor/bin/phpstan analyse -l max -c phpstan.neon src"
]
},
"extra": {
"branch-alias": {
"dev-master": "0.5.x-dev"
Expand Down
12 changes: 8 additions & 4 deletions phpstan.neon
@@ -1,5 +1,9 @@
includes:
- temp/phpstan/vendor/phpstan/phpstan-deprecation-rules/rules.neon
- temp/phpstan/vendor/phpstan/phpstan-nette/extension.neon
- temp/phpstan/vendor/phpstan/phpstan-nette/rules.neon
- temp/phpstan/vendor/phpstan/phpstan-strict-rules/rules.neon
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
- vendor/phpstan/phpstan-nette/extension.neon
- vendor/phpstan/phpstan-nette/rules.neon
- vendor/phpstan/phpstan-strict-rules/rules.neon

parameters:
ignoreErrors:
- '#^.+ should be (contravariant|covariant) with .+$#'
5 changes: 2 additions & 3 deletions ruleset.xml
Expand Up @@ -2,9 +2,8 @@
<ruleset name="Contributte">
<!-- Contributte Coding Standard -->
<rule ref="./vendor/ninjify/coding-standard/contributte.xml">
<exclude name="SlevomatCodingStandard.Commenting.ForbiddenAnnotations.AnnotationForbidden" />
<exclude name="Squiz.Commenting.FunctionComment.InvalidTypeHint" />
</rule>
<exclude name="Squiz.Commenting.FunctionComment.InvalidTypeHint"/>
</rule>

<!-- Specific rules -->
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
Expand Down
4 changes: 2 additions & 2 deletions src/AbstractLogger.php
Expand Up @@ -7,8 +7,6 @@

/**
* AbstractTracyLogger based on official Tracy\Logger (@copyright David Grudl)
*
* @author Milan Felix Sulc <sulcmil@gmail.com>
*/
abstract class AbstractLogger implements ILogger
{
Expand Down Expand Up @@ -44,12 +42,14 @@ protected function getExceptionFile(Throwable $exception): string
];
$exception = $exception->getPrevious();
}

$hash = substr(md5(serialize($data)), 0, 10);

foreach (new DirectoryIterator($this->directory) as $file) {
if ($file->isDot()) {
continue;
}

if ((bool) strpos($file->getBasename(), $hash)) {
return $file->getPathname();
}
Expand Down
2 changes: 0 additions & 2 deletions src/BlueScreenFileLogger.php
Expand Up @@ -11,8 +11,6 @@
* BlueScreenFileLogger based on official Tracy\Logger (@copyright David Grudl)
*
* Log every exception as single html file
*
* @author Milan Felix Sulc <sulcmil@gmail.com>
*/
class BlueScreenFileLogger extends AbstractLogger implements ILogger
{
Expand Down
11 changes: 9 additions & 2 deletions src/DI/SentryLoggingExtension.php
Expand Up @@ -33,7 +33,10 @@ public function loadConfiguration(): void
{
$builder = $this->getContainerBuilder();
$config = $this->config;
if ($config->enabled === false) return;

if ($config->enabled === false) {
return;
}

$builder->addDefinition($this->prefix('logger'))
->setFactory(SentryLogger::class, [(array) $config]);
Expand All @@ -46,9 +49,13 @@ public function beforeCompile(): void
{
$builder = $this->getContainerBuilder();
$config = $this->config;
if ($config->enabled === false) return;

if ($config->enabled === false) {
return;
}

$logger = $builder->getByType(UniversalLogger::class);

if ($logger === null) {
throw new ServiceCreationException(
sprintf(
Expand Down
1 change: 1 addition & 0 deletions src/DI/SlackLoggingExtension.php
Expand Up @@ -67,6 +67,7 @@ public function beforeCompile(): void
$builder = $this->getContainerBuilder();

$logger = $builder->getByType(UniversalLogger::class);

if ($logger === null) {
throw new ServiceCreationException(
sprintf(
Expand Down
2 changes: 2 additions & 0 deletions src/DI/TracyLoggingExtension.php
Expand Up @@ -38,11 +38,13 @@ public function loadConfiguration(): void
// Register defined loggers
if (count($config->loggers) !== 0) {
$loggers = [];

foreach ($config->loggers as $k => $v) {
$loggers[$this->prefix('logger.' . $k)] = $v;
}

$this->compiler->loadDefinitionsFromConfig($loggers);

foreach (array_keys($loggers) as $name) {
$logger->addSetup('addLogger', [$builder->getDefinition($name)]);
}
Expand Down
3 changes: 0 additions & 3 deletions src/Exceptions/Logical/InvalidStateException.php
Expand Up @@ -4,9 +4,6 @@

use Contributte\Logging\Exceptions\LogicalException;

/**
* @author Milan Felix Sulc <sulcmil@gmail.com>
*/
final class InvalidStateException extends LogicalException
{

Expand Down
3 changes: 0 additions & 3 deletions src/Exceptions/LogicalException.php
Expand Up @@ -4,9 +4,6 @@

use LogicException;

/**
* @author Milan Felix Sulc <sulcmil@gmail.com>
*/
abstract class LogicalException extends LogicException
{

Expand Down
3 changes: 0 additions & 3 deletions src/Exceptions/RuntimeException.php
Expand Up @@ -2,9 +2,6 @@

namespace Contributte\Logging\Exceptions;

/**
* @author Milan Felix Sulc <sulcmil@gmail.com>
*/
abstract class RuntimeException extends \RuntimeException
{

Expand Down
7 changes: 4 additions & 3 deletions src/FileLogger.php
Expand Up @@ -10,8 +10,6 @@
* FileLogger based on official Tracy\Logger (@copyright David Grudl)
*
* Log all messages to <priority>.log
*
* @author Milan Felix Sulc <sulcmil@gmail.com>
*/
class FileLogger extends AbstractLogger implements ILogger
{
Expand All @@ -25,7 +23,10 @@ public function log($message, string $priority = ILogger::INFO): void
throw new InvalidStateException('Directory "' . $this->directory . '" is not found or is not directory.');
}

$exceptionFile = ($message instanceof Throwable) ? $this->getExceptionFile($message) : null;
$exceptionFile = ($message instanceof Throwable)
? $this->getExceptionFile($message)
: null;

$line = Logger::formatLogLine($message, $exceptionFile);
$file = $this->directory . '/' . strtolower($priority) . '.log';

Expand Down
3 changes: 0 additions & 3 deletions src/ILogger.php
Expand Up @@ -4,9 +4,6 @@

use Tracy\ILogger as TracyLogger;

/**
* @author Milan Felix Sulc <sulcmil@gmail.com>
*/
interface ILogger
{

Expand Down
3 changes: 0 additions & 3 deletions src/Mailer/FileMailer.php
Expand Up @@ -5,9 +5,6 @@
use Tracy\Helpers;
use Tracy\Logger;

/**
* @author Milan Felix Sulc <sulcmil@gmail.com>
*/
class FileMailer implements IMailer
{

Expand Down
3 changes: 0 additions & 3 deletions src/Mailer/IMailer.php
Expand Up @@ -2,9 +2,6 @@

namespace Contributte\Logging\Mailer;

/**
* @author Milan Felix Sulc <sulcmil@gmail.com>
*/
interface IMailer
{

Expand Down
4 changes: 1 addition & 3 deletions src/Mailer/TracyMailer.php
Expand Up @@ -7,8 +7,6 @@

/**
* TracyMailer based on official Tracy\Logger[default mailer] (@copyright David Grudl)
*
* @author Milan Felix Sulc <sulcmil@gmail.com>
*/
class TracyMailer implements IMailer
{
Expand All @@ -22,7 +20,7 @@ class TracyMailer implements IMailer
/**
* @param mixed[] $to
*/
public function __construct(?string $from = null, array $to)
public function __construct(?string $from, array $to)
{
$this->from = $from;
$this->to = $to;
Expand Down
2 changes: 1 addition & 1 deletion src/NullLogger.php
Expand Up @@ -11,7 +11,7 @@ class NullLogger implements TracyLogger
* @param mixed $message
* @param string $priority
*/
public function log($message, $priority = self::INFO): void
public function log($message, $priority = self::INFO): void // phpcs:ignore
{
}

Expand Down
7 changes: 6 additions & 1 deletion src/SendMailLogger.php
Expand Up @@ -47,19 +47,24 @@ public function setMailer(IMailer $mailer): void
*/
public function log($message, string $priority = ILogger::INFO): void
{
if (!in_array($priority, $this->allowedPriority, true)) return;
if (!in_array($priority, $this->allowedPriority, true)) {
return;
}

if (is_numeric($this->emailSnooze)) {
$snooze = (int) $this->emailSnooze;
} else {
$strtotime = @strtotime($this->emailSnooze);

if ($strtotime === false) {
throw new InvalidArgumentException('Email snooze was not parsed');
}

$snooze = $strtotime - time();
}

$filemtime = @filemtime($this->directory . '/email-sent');

if ($filemtime === false) {
throw new InvalidStateException('File time cant be reached');
}
Expand Down
2 changes: 2 additions & 0 deletions src/Sentry/SentryLogger.php
Expand Up @@ -64,6 +64,7 @@ public function log($message, string $priority = ILogger::INFO): void
}

$level = $this->getLevel($priority);

if ($level === null) {
return;
}
Expand All @@ -85,6 +86,7 @@ protected function makeRequest($message, array $data): void
$this->configuration[self::CONFIG_URL],
$this->configuration[self::CONFIG_OPTIONS]
);

if ($message instanceof Throwable) {
$client->captureException($message, $data);
} else {
Expand Down

0 comments on commit 2b4da34

Please sign in to comment.