Skip to content

Commit bb263a8

Browse files
committed
Update dependencies.
Test on PHP 7.4 and 8+
1 parent 95036e9 commit bb263a8

15 files changed

+325
-289
lines changed

.github/workflows/php.yml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: PHP
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
run:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
include:
16+
- php: 7.4
17+
composer: '--prefer-lowest'
18+
desc: "Lowest versions"
19+
- php: 7.4
20+
- php: 8.0
21+
- php: 8.1
22+
- php: 8.2
23+
coverage: '--coverage-clover /tmp/clover.xml'
24+
- php: 8.3
25+
name: PHP ${{ matrix.php }} ${{ matrix.desc }}
26+
27+
steps:
28+
- uses: actions/checkout@v4
29+
with:
30+
fetch-depth: 2
31+
32+
- name: Setup PHP
33+
uses: shivammathur/setup-php@v2
34+
with:
35+
php-version: ${{ matrix.php }}
36+
coverage: xdebug
37+
38+
- name: Validate composer.json and composer.lock
39+
run: composer validate
40+
41+
- name: Install dependencies
42+
run: composer update --prefer-dist --no-progress ${{ matrix.composer }}
43+
44+
- name: Run PHPUnit
45+
run: vendor/bin/phpunit ${{ matrix.coverage }}
46+
47+
- name: Upload Scrutinizer coverage
48+
uses: sudo-bot/action-scrutinizer@latest
49+
if: ${{ matrix.coverage }}
50+
with:
51+
cli-args: "--format=php-clover build/logs/clover.xml --revision=${{ github.event.pull_request.head.sha || github.sha }}"

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/vendor
22
/composer.lock
33
.phpunit.result.cache
4+
.idea

.travis.yml

-26
This file was deleted.

composer.json

+17-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"source": "https://github.com/jasny/twig-extensions"
1717
},
1818
"require": {
19-
"php": ">=7.0.0",
19+
"php": ">=7.4.0",
2020
"twig/twig": "^2.0 | ^3.0"
2121
},
2222
"suggest": {
@@ -29,14 +29,26 @@
2929
}
3030
},
3131
"require-dev": {
32-
"php": ">=7.2.0",
32+
"php": ">=7.4.0",
3333
"ext-intl": "*",
3434
"ext-pcre": "*",
35-
"jasny/php-code-quality": "^2.5"
35+
"ext-json": "*",
36+
"phpstan/phpstan": "^1.12.0",
37+
"phpunit/phpunit": "^9.6",
38+
"squizlabs/php_codesniffer": "^3.10"
3639
},
3740
"autoload-dev": {
38-
"classmap": [
39-
"tests/support/"
41+
"psr-4": {
42+
"Jasny\\Twig\\Tests\\": "tests/"
43+
}
44+
},
45+
"minimum-stability": "dev",
46+
"prefer-stable": true,
47+
"scripts": {
48+
"test": [
49+
"phpstan analyse",
50+
"XDEBUG_MODE=coverage phpunit --testdox --colors=always --coverage-text",
51+
"phpcs -p src"
4052
]
4153
}
4254
}

phpstan.neon

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
parameters:
2+
level: 5
3+
paths:
4+
- src
5+

phpunit.xml.dist

+11-22
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
3-
<phpunit
4-
colors="true"
5-
bootstrap="vendor/autoload.php"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
>
10-
<testsuites>
11-
<testsuite name="tests">
12-
<directory>tests/</directory>
13-
</testsuite>
14-
</testsuites>
15-
<filter>
16-
<whitelist processUncoveredFilesFromWhitelist="true">
17-
<directory suffix=".php">src</directory>
18-
</whitelist>
19-
</filter>
20-
<logging>
21-
<log type="coverage-text" target="php://stdout"/>
22-
</logging>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="vendor/autoload.php" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3+
<coverage processUncoveredFiles="true">
4+
<include>
5+
<directory suffix=".php">src</directory>
6+
</include>
7+
</coverage>
8+
<testsuites>
9+
<testsuite name="tests">
10+
<directory>tests/</directory>
11+
</testsuite>
12+
</testsuites>
2313
</phpunit>
24-

src/ArrayExtension.php

+10-18
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ class ArrayExtension extends AbstractExtension
1212
{
1313
/**
1414
* Return extension name
15-
*
16-
* @return string
1715
*/
18-
public function getName()
16+
public function getName(): string
1917
{
2018
return 'jasny/array';
2119
}
@@ -38,44 +36,38 @@ public function getFilters()
3836

3937
/**
4038
* Calculate the sum of values in an array
41-
*
42-
* @param array $array
43-
* @return int
4439
*/
45-
public function sum($array)
40+
public function sum(?array $array): ?int
4641
{
4742
return isset($array) ? array_sum((array)$array) : null;
4843
}
4944

5045
/**
5146
* Calculate the product of values in an array
52-
*
53-
* @param array $array
54-
* @return int
5547
*/
56-
public function product($array)
48+
public function product(?array $array): ?int
5749
{
5850
return isset($array) ? array_product((array)$array) : null;
5951
}
6052

6153
/**
6254
* Return all the values of an array or object
6355
*
64-
* @param array|object $array
65-
* @return array
56+
* @param array|object|null $array
57+
* @return array|null
6658
*/
67-
public function values($array)
59+
public function values($array): ?array
6860
{
6961
return isset($array) ? array_values((array)$array) : null;
7062
}
7163

7264
/**
7365
* Cast value to an array
7466
*
75-
* @param object|mixed $value
67+
* @param mixed $value
7668
* @return array
7769
*/
78-
public function asArray($value)
70+
public function asArray($value): array
7971
{
8072
return is_object($value) ? get_object_vars($value) : (array)$value;
8173
}
@@ -84,9 +76,9 @@ public function asArray($value)
8476
* Cast an array to an HTML attribute string
8577
*
8678
* @param mixed $array
87-
* @return string
79+
* @return string|null
8880
*/
89-
public function htmlAttributes($array)
81+
public function htmlAttributes($array): ?string
9082
{
9183
if (!isset($array)) {
9284
return null;

0 commit comments

Comments
 (0)