Skip to content

Commit

Permalink
Update dependencies.
Browse files Browse the repository at this point in the history
Test on PHP 7.4 and 8+
  • Loading branch information
jasny committed Sep 2, 2024
1 parent 95036e9 commit bb263a8
Show file tree
Hide file tree
Showing 15 changed files with 325 additions and 289 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: PHP

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
run:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- php: 7.4
composer: '--prefer-lowest'
desc: "Lowest versions"
- php: 7.4
- php: 8.0
- php: 8.1
- php: 8.2
coverage: '--coverage-clover /tmp/clover.xml'
- php: 8.3
name: PHP ${{ matrix.php }} ${{ matrix.desc }}

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: xdebug

- name: Validate composer.json and composer.lock
run: composer validate

- name: Install dependencies
run: composer update --prefer-dist --no-progress ${{ matrix.composer }}

- name: Run PHPUnit
run: vendor/bin/phpunit ${{ matrix.coverage }}

- name: Upload Scrutinizer coverage
uses: sudo-bot/action-scrutinizer@latest
if: ${{ matrix.coverage }}
with:
cli-args: "--format=php-clover build/logs/clover.xml --revision=${{ github.event.pull_request.head.sha || github.sha }}"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/vendor
/composer.lock
.phpunit.result.cache
.idea
26 changes: 0 additions & 26 deletions .travis.yml

This file was deleted.

22 changes: 17 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"source": "https://github.com/jasny/twig-extensions"
},
"require": {
"php": ">=7.0.0",
"php": ">=7.4.0",
"twig/twig": "^2.0 | ^3.0"
},
"suggest": {
Expand All @@ -29,14 +29,26 @@
}
},
"require-dev": {
"php": ">=7.2.0",
"php": ">=7.4.0",
"ext-intl": "*",
"ext-pcre": "*",
"jasny/php-code-quality": "^2.5"
"ext-json": "*",
"phpstan/phpstan": "^1.12.0",
"phpunit/phpunit": "^9.6",
"squizlabs/php_codesniffer": "^3.10"
},
"autoload-dev": {
"classmap": [
"tests/support/"
"psr-4": {
"Jasny\\Twig\\Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"test": [
"phpstan analyse",
"XDEBUG_MODE=coverage phpunit --testdox --colors=always --coverage-text",
"phpcs -p src"
]
}
}
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: 5
paths:
- src

33 changes: 11 additions & 22 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit
colors="true"
bootstrap="vendor/autoload.php"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<testsuites>
<testsuite name="tests">
<directory>tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-text" target="php://stdout"/>
</logging>
<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">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="tests">
<directory>tests/</directory>
</testsuite>
</testsuites>
</phpunit>

28 changes: 10 additions & 18 deletions src/ArrayExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ class ArrayExtension extends AbstractExtension
{
/**
* Return extension name
*
* @return string
*/
public function getName()
public function getName(): string
{
return 'jasny/array';
}
Expand All @@ -38,44 +36,38 @@ public function getFilters()

/**
* Calculate the sum of values in an array
*
* @param array $array
* @return int
*/
public function sum($array)
public function sum(?array $array): ?int
{
return isset($array) ? array_sum((array)$array) : null;
}

/**
* Calculate the product of values in an array
*
* @param array $array
* @return int
*/
public function product($array)
public function product(?array $array): ?int
{
return isset($array) ? array_product((array)$array) : null;
}

/**
* Return all the values of an array or object
*
* @param array|object $array
* @return array
* @param array|object|null $array
* @return array|null
*/
public function values($array)
public function values($array): ?array
{
return isset($array) ? array_values((array)$array) : null;
}

/**
* Cast value to an array
*
* @param object|mixed $value
* @param mixed $value
* @return array
*/
public function asArray($value)
public function asArray($value): array
{
return is_object($value) ? get_object_vars($value) : (array)$value;
}
Expand All @@ -84,9 +76,9 @@ public function asArray($value)
* Cast an array to an HTML attribute string
*
* @param mixed $array
* @return string
* @return string|null
*/
public function htmlAttributes($array)
public function htmlAttributes($array): ?string
{
if (!isset($array)) {
return null;
Expand Down
Loading

0 comments on commit bb263a8

Please sign in to comment.