Skip to content

Commit

Permalink
PHP 7.1, coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
mabar authored and Milan Felix Šulc committed Jun 21, 2018
1 parent 5355bce commit 6c02777
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 77 deletions.
20 changes: 7 additions & 13 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# IDE
/.idea

# Folders
# Composer
/vendor

# Files
/composer.lock

# Tests
/temp/
/tests/*.log
/tests/tmp
/tests/coverage.html
/coverage.xml
21 changes: 14 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
language: php

php:
- 7.1
- 7.2
- 7.1
- 7.2

before_install:
# turn off XDebug
Expand All @@ -24,28 +25,34 @@ jobs:
script:
- composer run-script tester

- 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
19 changes: 12 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"name": "contributte/latte-parsedown-extra",
"description": "ParsedownExtra parser for Latte",
"type": "library",
"license": ["MIT"],
"license": [
"MIT"
],
"homepage": "https://github.com/contributte/latte-parsedown-extra",
"authors": [
{
Expand All @@ -11,18 +13,20 @@
}
],
"require": {
"php": ">=5.6.0",
"php": ">= 7.1",
"nette/di": "~2.4.10",
"nette/utils": "~2.4.9",
"nette/utils": "~2.5.2",
"latte/latte": "~2.4.7",
"erusev/parsedown-extra": "^0.7.1",
"erusev/parsedown": "~1.7.1"
},
"require-dev": {
"ninjify/qa": "^0.4.0",
"ninjify/qa": "^0.8.0",
"ninjify/nunjuck": "^0.2.0",
"nette/application": "~2.4.9"
},
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-4": {
"Contributte\\Parsedown\\": "src/"
Expand All @@ -41,11 +45,12 @@
],
"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"
]
}
}
3 changes: 1 addition & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -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:
11 changes: 10 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ composer require contributte/latte-parsedown-extra

| State | Version | Branch | PHP |
|-------------|----------|----------|----------|
| stable | `^1.1.0` | `master` | `>= 5.6` |
| dev | `^1.4.0` | `master` | `>= 7.1` |
| stable | `^1.3.0` | `master` | `>= 7.1` |
| stable | `^1.2.0` | `master` | `>= 5.6` |

## Overview

Expand All @@ -46,6 +48,13 @@ composer require contributte/latte-parsedown-extra
</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
9 changes: 6 additions & 3 deletions ruleset.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?xml version="1.0"?>
<ruleset name="Markette">
<!-- Extending rulesets -->
<rule ref="vendor/ninjify/coding-standard/ruleset.xml"/>
<!-- My rules -->
<!-- Contributte Coding Standard -->
<rule ref="./vendor/ninjify/coding-standard/contributte.xml">
<exclude name="Squiz.Commenting.FunctionComment.InvalidTypeHint"/>
</rule>

<!-- Specific rules -->
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
<properties>
<property name="rootNamespaces" type="array" value="
Expand Down
21 changes: 8 additions & 13 deletions src/DI/ParsedownExtraExtension.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
<?php
<?php declare(strict_types = 1);

namespace Contributte\Parsedown\DI;

use Contributte\Parsedown\ParsedownExtraAdapter;
use Contributte\Parsedown\ParsedownFilter;
use Nette\Bridges\ApplicationLatte\ILatteFactory;
use Nette\DI\CompilerExtension;
use Nette\DI\Statement;
use Nette\InvalidStateException;

/**
* ParsedownExtra Extension
*
* @author Milan Felix Sulc <[email protected]>
*/
class ParsedownExtraExtension extends CompilerExtension
{

/** @var array */
/** @var mixed[] */
private $defaults = [
'helper' => 'parsedown',
];

/**
* Register services
*
* @return void
*/
public function loadConfiguration()
public function loadConfiguration(): void
{
$this->validateConfig($this->defaults);
$builder = $this->getContainerBuilder();
Expand All @@ -37,17 +34,15 @@ public function loadConfiguration()

/**
* Decorate services
*
* @return void
*/
public function beforeCompile()
public function beforeCompile(): void
{
$config = $this->validateConfig($this->defaults);
$builder = $this->getContainerBuilder();

$templateFactory = $builder->getByType('Nette\Bridges\ApplicationLatte\ILatteFactory');
if (!$templateFactory) {
throw new InvalidStateException('Service implemented Nette\Bridges\ApplicationLatte\ILatteFactory not found.');
$templateFactory = $builder->getByType(ILatteFactory::class);
if ($templateFactory === null) {
throw new InvalidStateException(sprintf('Service which implements %s not found.', ILatteFactory::class));
}

$builder->getDefinition($templateFactory)
Expand Down
14 changes: 5 additions & 9 deletions src/ParsedownExtraAdapter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

namespace Contributte\Parsedown;

Expand All @@ -8,7 +8,6 @@
/**
* ParsedownExtra Adapter
*
* @author Milan Felix Sulc <[email protected]>
* @method void onProcess(string $text, ParsedownExtraAdapter $adapter)
*/
class ParsedownExtraAdapter
Expand All @@ -19,17 +18,15 @@ class ParsedownExtraAdapter
/** @var ParsedownExtra */
private $parsedown;

/** @var array */
/** @var callable[] */
public $onProcess = [];

/**
* Creates adapter
*
* @param ParsedownExtra|NULL $parsedown
*/
public function __construct(ParsedownExtra $parsedown = NULL)
public function __construct(?ParsedownExtra $parsedown = null)
{
$this->parsedown = $parsedown ? $parsedown : new ParsedownExtra();
$this->parsedown = $parsedown ?: new ParsedownExtra();
}

/**
Expand All @@ -45,9 +42,8 @@ public function process($text)

/**
* @param mixed $line
* @return string
*/
public function processLine($line)
public function processLine($line): string
{
$this->onProcess($line, $this);

Expand Down
9 changes: 2 additions & 7 deletions src/ParsedownFilter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

namespace Contributte\Parsedown;

Expand All @@ -11,20 +11,15 @@ class ParsedownFilter
/** @var ParsedownExtraAdapter */
protected $adapter;

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

/**
* @param FilterInfo $info
* @param mixed $text
* @return Html
*/
public function apply(FilterInfo $info, $text)
public function apply(FilterInfo $info, $text): Html
{
return new Html($this->adapter->process($text));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

use Ninjify\Nunjuck\Environment;

Expand Down
13 changes: 6 additions & 7 deletions tests/cases/DI/ParsedownExtraExtension.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

<?php declare(strict_types = 1);

use Contributte\Parsedown\DI\ParsedownExtraExtension;
use Nette\Bridges\ApplicationDI\LatteExtension;
Expand All @@ -12,11 +11,11 @@ use Tester\FileMock;

require_once __DIR__ . '/../../bootstrap.php';

test(function () {
$loader = new ContainerLoader(TEMP_DIR, TRUE);
$class = $loader->load(function (Compiler $compiler) {
$compiler->addExtension('console', new ParsedownExtraExtension());
test(function (): void {
$loader = new ContainerLoader(TEMP_DIR, true);
$class = $loader->load(function (Compiler $compiler): void {
$compiler->addExtension('latte', new LatteExtension(TEMP_DIR));
$compiler->addExtension('parsedown', new ParsedownExtraExtension());
$compiler->loadConfig(FileMock::create('
services:
latte.latteFactory:
Expand All @@ -26,7 +25,7 @@ test(function () {
}, [microtime(), 1]);

/** @var Container $container */
$container = new $class;
$container = new $class();

$text = '
{block|parsedown}
Expand Down
4 changes: 2 additions & 2 deletions tests/cases/ParsedownExtraAdapter.phpt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
<?php declare(strict_types = 1);

use Contributte\Parsedown\ParsedownExtraAdapter;
use Tester\Assert;

require __DIR__ . '/../bootstrap.php';

test(function () {
test(function (): void {
$adapter = new ParsedownExtraAdapter();

$text = '
Expand Down
4 changes: 2 additions & 2 deletions tests/cases/ParsedownFilter.phpt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

use Contributte\Parsedown\ParsedownExtraAdapter;
use Contributte\Parsedown\ParsedownFilter;
Expand All @@ -8,7 +8,7 @@ use Tester\Assert;

require __DIR__ . '/../bootstrap.php';

test(function () {
test(function (): void {
$adapter = new ParsedownExtraAdapter();
$latte = new Engine();
$latte->addFilter('parsedown', [new ParsedownFilter($adapter), 'apply']);
Expand Down

0 comments on commit 6c02777

Please sign in to comment.