Skip to content

Commit f21583d

Browse files
mabarMilan Felix Šulc
authored andcommitted
PHP7.1, code style, phpstan
1 parent 4414fc0 commit f21583d

28 files changed

+277
-334
lines changed

.docs/README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ use Contributte\Latte\Filters\FiltersProvider;
6464
final class MyFilters implements FiltersProvider
6565
{
6666
67-
/**
68-
* @return array
69-
*/
70-
public function getFilters()
67+
/**
68+
* @return callable[]
69+
*/
70+
public function getFilters(): array
7171
{
7272
return [
7373
'say' => function ($hi) {
@@ -117,21 +117,21 @@ This is my email: <a href="mailto: my[at]email.org">my[at]email.org</a>
117117

118118
### `NumberFormatter`
119119

120-
Number formatter is simple wrapping class over `number_format` method.
120+
Number formatter is simple wrapping class over `number_format` method.
121121

122122
```yaml
123123
services:
124-
formatter.money:
124+
formatter.money:
125125
# with defined prefix
126-
class: Contributte\Latte\Formatters\NumberFormatter('Kč')
127-
128-
formatter.weight:
126+
class: Contributte\Latte\Formatters\NumberFormatter('Kč')
127+
128+
formatter.weight:
129129
# with defined prefix and suffix
130130
class: Contributte\Latte\Formatters\NumberFormatter('kg', '~')
131131
setup:
132-
- setThousands(NULL)
132+
- setThousands('')
133133
- setDecimals(0)
134-
134+
135135
nette.latteFactory:
136136
setup:
137137
# used as latte filter

.editorconfig

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
# EditorConfig is awesome: http://EditorConfig.org
22

3-
# Top-most EditorConfig file
43
root = true
54

6-
# Unix-style newlines with a newline ending every file
75
[*]
6+
charset = utf-8
87
end_of_line = lf
98
insert_final_newline = true
10-
11-
# JS / PHP
12-
[*.{js,php,phpt}]
13-
charset = utf-8
9+
trim_trailing_whitespace = true
1410
indent_style = tab
15-
indent_size = 4
11+
indent_size = tab
12+
tab_width = 4
1613

17-
# NEON
18-
[*.neon]
19-
charset = utf-8
20-
indent_style = tab
14+
[*.md]
15+
indent_style = space
2116
indent_size = 4
2217

23-
# Composer, NPM, Travis, BitbucketPipelines
24-
[{composer.json,package.json,.travis.yml,bitbucket-pipelines.yml}]
18+
[{composer.json,package.json,.travis.yml}]
2519
indent_style = space
2620
indent_size = 2

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
# IDE
2+
/.idea
3+
14
# Composer
25
/vendor
36
/composer.lock
47

58
# Tests
9+
/temp/
610
/tests/*.log
711
/tests/tmp
812
/tests/coverage.html
13+
/coverage.xml

.travis.yml

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,58 @@
11
language: php
22

33
php:
4-
- 5.6
5-
- 7.0
64
- 7.1
7-
- hhvm
5+
- 7.2
86

9-
matrix:
10-
fast_finish: true
7+
before_install:
8+
# turn off XDebug
9+
- phpenv config-rm xdebug.ini || return 0
1110

12-
allow_failures:
13-
- php: hhvm
14-
15-
include:
16-
- php: 5.6
17-
env: COMPOSER_FLAG=--prefer-lowest
18-
- php: 5.6
19-
env: COMPOSER_FLAG=--prefer-stable
20-
- php: 7.0
21-
env: COMPOSER_FLAG=--prefer-lowest
22-
- php: 7.0
23-
env: COMPOSER_FLAG=--prefer-stable
24-
- php: 7.1
25-
env: COMPOSER_FLAG=--prefer-lowest
26-
- php: 7.1
27-
env: COMPOSER_FLAG=--prefer-stable
28-
29-
before_script:
11+
install:
3012
# Composer
31-
- travis_retry composer install --no-interaction
32-
# Coverage
33-
- if [[ "$TRAVIS_PHP_VERSION" == "7.1" && "$COMPOSER_FLAG" == "" ]]; then COVERAGE=1; fi
13+
- travis_retry composer install --no-progress --prefer-dist
3414

3515
script:
36-
# Quality Assurance
37-
- travis_retry composer qa
38-
39-
# Nette\Tester
16+
# Nette/Tester
4017
- composer run-script tester
4118

42-
# Nette\Tester + CodeCoverage
43-
- if [ "$COVERAGE" != "" ]; then composer tester-coverage; fi
19+
jobs:
20+
include:
21+
- env: title="Lowest Dependencies 7.1"
22+
php: 7.1
23+
install:
24+
- travis_retry composer update --no-progress --prefer-dist --prefer-lowest
25+
script:
26+
- composer run-script tester
27+
28+
- env: title="Lowest Dependencies 7.2"
29+
php: 7.2
30+
install:
31+
- travis_retry composer update --no-progress --prefer-dist --prefer-lowest
32+
script:
33+
- composer run-script tester
34+
35+
- stage: Quality Assurance
36+
php: 7.2
37+
script:
38+
- composer run-script qa
39+
40+
- stage: Test Coverage
41+
php: 7.2
42+
script:
43+
- composer run-script coverage
44+
after_script:
45+
- wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.0.0/php-coveralls.phar
46+
- php coveralls.phar --verbose --config tests/.coveralls.yml
4447

45-
after_script:
46-
# Coverage (Coveralls)
47-
- if [ "$COVERAGE" != "" ]; then wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar; fi
48-
- if [ "$COVERAGE" != "" ]; then php coveralls.phar --verbose --config tests/.coveralls.yml; fi
48+
- stage: Phpstan
49+
php: 7.2
50+
script:
51+
- composer run-script phpstan-install
52+
- composer run-script phpstan
53+
54+
allow_failures:
55+
- stage: Test Coverage
4956

5057
after_failure:
5158
# Print *.actual content

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ composer require contributte/latte
2626

2727
| State | Version | Branch | PHP |
2828
|-------------|---------|----------|----------|
29+
| dev | `^0.4` | `master` | `>= 7.1` |
30+
| stable | `^0.3` | `master` | `>= 7.1` |
2931
| stable | `^0.2` | `master` | `>= 5.6` |
3032

3133
## Overview
@@ -48,6 +50,13 @@ composer require contributte/latte
4850
</br>
4951
<a href="https://github.com/f3l1x">Milan Felix Šulc</a>
5052
</td>
53+
<td align="center">
54+
<a href="https://github.com/mabar">
55+
<img width="150" height="150" src="https://avatars0.githubusercontent.com/u/20974277?s=400&v=4">
56+
</a>
57+
</br>
58+
<a href="https://github.com/mabar">Marek Bartoš</a>
59+
</td>
5160
</tr>
5261
<tbody>
5362
</table>

composer.json

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
{
22
"name": "contributte/latte",
33
"description": "Extra contrib to nette/latte",
4-
"keywords": ["nette", "latte", "extra"],
4+
"keywords": [
5+
"nette",
6+
"latte",
7+
"extra"
8+
],
59
"type": "library",
6-
"license": ["MIT"],
10+
"license": [
11+
"MIT"
12+
],
713
"homepage": "https://github.com/contributte/latte",
814
"authors": [
915
{
@@ -12,18 +18,23 @@
1218
}
1319
],
1420
"require": {
15-
"php": ">= 5.6",
16-
"latte/latte": "^2.4.4"
21+
"php": ">= 7.1",
22+
"latte/latte": "~2.4.4"
1723
},
1824
"require-dev": {
19-
"ninjify/qa": "^0.4.0",
20-
"ninjify/nunjuck": "^0.1.4",
21-
"nette/application": "^2.4.6",
22-
"nette/di": "^2.4.8"
25+
"ninjify/qa": "^0.8.0",
26+
"ninjify/nunjuck": "^0.2.0",
27+
"nette/application": "~2.4.6",
28+
"nette/di": "~2.4.12"
29+
},
30+
"conflict": {
31+
"nette/utils": "<2.5.2"
2332
},
2433
"suggest": {
2534
"nette/di": "to use VersionExtension[CompilerExtension]"
2635
},
36+
"minimum-stability": "dev",
37+
"prefer-stable": true,
2738
"autoload": {
2839
"psr-4": {
2940
"Contributte\\Latte\\": "src"
@@ -42,8 +53,17 @@
4253
"tester": [
4354
"tester -s -p php --colors 1 -c tests/php-unix.ini tests/cases"
4455
],
45-
"tester-coverage": [
56+
"coverage": [
4657
"tester -s -p php --colors 1 -c tests/php-unix.ini -d extension=xdebug.so --coverage ./coverage.xml --coverage-src ./src tests/cases"
58+
],
59+
"phpstan-install": [
60+
"mkdir -p temp/phpstan",
61+
"composer require -d temp/phpstan phpstan/phpstan:0.9.2",
62+
"composer require -d temp/phpstan phpstan/phpstan-nette:0.9",
63+
"composer require -d temp/phpstan phpstan/phpstan-strict-rules:0.9"
64+
],
65+
"phpstan": [
66+
"temp/phpstan/vendor/bin/phpstan analyse -l max -c phpstan.neon src"
4767
]
4868
}
4969
}

phpstan.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
includes:
2+
- temp/phpstan/vendor/phpstan/phpstan-strict-rules/rules.neon
3+
- temp/phpstan/vendor/phpstan/phpstan-nette/extension.neon
4+
- temp/phpstan/vendor/phpstan/phpstan-nette/rules.neon

ruleset.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Contributte">
3+
<!-- Contributte Coding Standard -->
4+
<rule ref="./vendor/ninjify/coding-standard/contributte.xml">
5+
<exclude name="SlevomatCodingStandard.Operators.DisallowIncrementAndDecrementOperators.DisallowedPostIncrementOperator"/>
6+
</rule>
7+
8+
<!-- Specific rules -->
9+
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
10+
<properties>
11+
<property name="rootNamespaces" type="array" value="
12+
src=>Contributte\Latte,
13+
tests/fixtures=>Tests\Fixtures
14+
"/>
15+
</properties>
16+
</rule>
17+
18+
<!-- Exclude folders -->
19+
<exclude-pattern>/tests/tmp</exclude-pattern>
20+
</ruleset>

src/DI/FiltersExtension.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types = 1);
22

33
namespace Contributte\Latte\DI;
44

@@ -7,23 +7,17 @@
77
use Nette\Bridges\ApplicationLatte\ILatteFactory;
88
use Nette\DI\CompilerExtension;
99

10-
/**
11-
* @author Milan Felix Sulc <sulcmil@gmail.com>
12-
* @author Tomas Votruba <info@tomasvotruba.cz>
13-
*/
1410
class FiltersExtension extends CompilerExtension
1511
{
1612

1713
/**
1814
* Decorate services
19-
*
20-
* @return void
2115
*/
22-
public function beforeCompile()
16+
public function beforeCompile(): void
2317
{
2418
$builder = $this->getContainerBuilder();
2519

26-
if ($builder->getByType(ILatteFactory::class) === NULL) {
20+
if ($builder->getByType(ILatteFactory::class) === null) {
2721
throw new LatteDefinitionNotFoundException();
2822
}
2923

src/DI/VersionExtension.php

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types = 1);
22

33
namespace Contributte\Latte\DI;
44

@@ -8,38 +8,33 @@
88
use Nette\DI\CompilerExtension;
99
use Nette\PhpGenerator\PhpLiteral;
1010

11-
/**
12-
* @author Milan Felix Sulc <sulcmil@gmail.com>
13-
*/
1411
class VersionExtension extends CompilerExtension
1512
{
1613

17-
/** @var array */
14+
/** @var mixed[] */
1815
private $defaults = [
19-
'debug' => FALSE,
20-
'rev' => NULL,
21-
'build' => NULL,
22-
'v' => NULL,
16+
'debug' => false,
17+
'rev' => null,
18+
'build' => null,
19+
'v' => null,
2320
];
2421

2522
/**
2623
* Decorate services
27-
*
28-
* @return void
2924
*/
30-
public function beforeCompile()
25+
public function beforeCompile(): void
3126
{
3227
$builder = $this->getContainerBuilder();
3328
$config = $this->validateConfig($this->defaults);
3429

35-
if ($builder->getByType(ILatteFactory::class) === NULL) {
30+
if ($builder->getByType(ILatteFactory::class) === null) {
3631
throw new LatteDefinitionNotFoundException();
3732
}
3833

39-
if ($config['debug'] === TRUE) {
40-
$config['rev'] = md5(microtime() . mt_rand(0, 100));
41-
$config['build'] = md5(microtime() . mt_rand(0, 100));
42-
$config['v'] = md5(microtime() . mt_rand(0, 100));
34+
if ($config['debug'] === true) {
35+
$config['rev'] = md5(microtime() . random_int(0, 100));
36+
$config['build'] = md5(microtime() . random_int(0, 100));
37+
$config['v'] = md5(microtime() . random_int(0, 100));
4338
}
4439

4540
$builder->getDefinitionByType(ILatteFactory::class)

0 commit comments

Comments
 (0)