diff --git a/.editorconfig b/.editorconfig index 7eb147b..f5bb015 100644 --- a/.editorconfig +++ b/.editorconfig @@ -21,3 +21,11 @@ insert_final_newline = true trim_trailing_whitespace = true indent_style = space indent_size = 2 + +[*.neon] +indent_style = tab +indent_size = 4 + +[composer.json] +indent_style = space +indent_size = 4 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f023555..3703ef1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,47 +1,47 @@ -name: Tests +name: tests -on: [push, pull_request] +on: [ push, pull_request ] jobs: - tests: - name: Tests PHP ${{ matrix.php }} - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - php: [7.4, 8.0, 8.1, 8.2] - include: - - php: 8.1 - analysis: true - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Set up PHP ${{ matrix.php }} - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - coverage: xdebug - - - name: Install dependencies with Composer - uses: ramsey/composer-install@v1 - - - name: Coding standards - if: matrix.analysis - run: vendor/bin/phpcs - - - name: Static analysis - if: matrix.analysis - run: vendor/bin/phpstan - - - name: Tests - run: vendor/bin/phpunit --coverage-clover clover.xml - - - name: Upload coverage results to Coveralls - if: matrix.analysis - env: - COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - composer require php-coveralls/php-coveralls -n -W - vendor/bin/php-coveralls --coverage_clover=clover.xml -v + tests: + name: Tests PHP ${{ matrix.php }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php: [ 7.4, 8.0, 8.1, 8.2, 8.3 ] + include: + - php: 8.2 + analysis: true + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up PHP ${{ matrix.php }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: xdebug + + - name: Install dependencies + run: composer install --prefer-dist --no-progress --no-suggest + + - name: Coding standards + if: matrix.analysis + run: composer sniffer:check + + - name: Static analysis + if: matrix.analysis + run: composer stan + + - name: Tests + run: composer test:coverage + + - name: Upload coverage results to Coveralls + if: matrix.analysis + env: + COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + composer require php-coveralls/php-coveralls -n -W + vendor/bin/php-coveralls --coverage_clover=build/coverage/clover.xml -v diff --git a/.gitignore b/.gitignore index 6690570..d1e4bf6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,18 @@ -.*.swp -.idea -.phpunit.result.cache +# Composer composer.lock +/vendor + +# PHPUnit +/.phpunit.cache +.phpunit.result.cache + +# IDEs +/.fleet +/.idea +/.vscode + +# Build artifacts and temporary files +.DS_Store clover.xml -coverage -vendor +/build +/coverage diff --git a/README.md b/README.md index 0b75eed..dbb48a1 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,10 @@ # Slim Framework Twig View -[![Build Status](https://travis-ci.org/slimphp/Twig-View.svg?branch=master)](https://travis-ci.org/slimphp/Twig-View) +[![Latest Version on Packagist](https://img.shields.io/github/release/slimphp/twig-view.svg)](https://packagist.org/packages/slim/Twig-View) +[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE.md) +[![Build Status](https://github.com/slimphp/Twig-View/actions/workflows/tests.yml/badge.svg?branch=3.x)](https://github.com/slimphp/Twig-View/actions) [![Coverage Status](https://coveralls.io/repos/github/slimphp/Twig-View/badge.svg?branch=3.x)](https://coveralls.io/github/slimphp/Twig-View?branch=3.x) -[![License](https://poser.pugx.org/slim/twig-view/license)](https://packagist.org/packages/slim/twig-view) +[![Total Downloads](https://img.shields.io/packagist/dt/slim/Twig-View.svg)](https://packagist.org/packages/slim/Twig-View/stats) This is a Slim Framework view helper built on top of the Twig templating component. You can use this component to create and render templates in your Slim Framework application. @@ -11,7 +13,7 @@ This is a Slim Framework view helper built on top of the Twig templating compone Via [Composer](https://getcomposer.org/) ```bash -$ composer require slim/twig-view +composer require slim/twig-view ``` Requires Slim Framework 4, Twig 3 and PHP 7.4 or newer. diff --git a/composer.json b/composer.json index 9eda381..656091d 100644 --- a/composer.json +++ b/composer.json @@ -1,10 +1,15 @@ { "name": "slim/twig-view", - "type": "library", "description": "Slim Framework 4 view helper built on top of the Twig 3 templating component", - "keywords": ["slim","framework","view","template","twig"], - "homepage": "https://www.slimframework.com", "license": "MIT", + "type": "library", + "keywords": [ + "slim", + "framework", + "view", + "template", + "twig" + ], "authors": [ { "name": "Josh Lockhart", @@ -17,17 +22,18 @@ "homepage": "http://www.lgse.com" } ], + "homepage": "https://www.slimframework.com", "require": { "php": "^7.4 || ^8.0", "psr/http-message": "^1.1 || ^2.0", "slim/slim": "^4.12", - "twig/twig": "^3.8", - "symfony/polyfill-php81": "^1.29" + "symfony/polyfill-php81": "^1.29", + "twig/twig": "^3.8" }, "require-dev": { - "phpunit/phpunit": "^9.6", "phpspec/prophecy-phpunit": "^2.0", "phpstan/phpstan": "^1.10.59", + "phpunit/phpunit": "^9.6 || ^10", "psr/http-factory": "^1.0", "squizlabs/php_codesniffer": "^3.9" }, @@ -42,13 +48,18 @@ } }, "scripts": { - "test": [ - "@phpunit", - "@phpcs", - "@phpstan" + "sniffer:check": "phpcs --standard=phpcs.xml", + "sniffer:fix": "phpcbf --standard=phpcs.xml", + "stan": "phpstan analyse -c phpstan.neon --no-progress --ansi", + "test": "phpunit --configuration phpunit.xml --do-not-cache-result --colors=always", + "test:all": [ + "@sniffer:check", + "@stan", + "@test:coverage" ], - "phpunit": "phpunit", - "phpcs": "phpcs", - "phpstan": "phpstan" + "test:coverage": [ + "@putenv XDEBUG_MODE=coverage", + "phpunit --configuration phpunit.xml --do-not-cache-result --colors=always --coverage-clover build/coverage/clover.xml --coverage-html build/coverage --coverage-text" + ] } } diff --git a/phpcs.xml.dist b/phpcs.xml similarity index 100% rename from phpcs.xml.dist rename to phpcs.xml diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..a901dbb --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,6 @@ +parameters: + level: 8 + paths: + - src + ignoreErrors: + - message: '#Method (.*) has parameter (.*) with generic class Slim\\App but does not specify its types: TContainerInterface#' \ No newline at end of file diff --git a/phpstan.neon.dist b/phpstan.neon.dist deleted file mode 100644 index 6e7968f..0000000 --- a/phpstan.neon.dist +++ /dev/null @@ -1,4 +0,0 @@ -parameters: - level: max - paths: - - src diff --git a/phpunit.xml.dist b/phpunit.xml similarity index 100% rename from phpunit.xml.dist rename to phpunit.xml diff --git a/src/Twig.php b/src/Twig.php index 3b8c3ef..2d94464 100644 --- a/src/Twig.php +++ b/src/Twig.php @@ -63,7 +63,7 @@ class Twig implements ArrayAccess /** * @param ServerRequestInterface $request - * @param string $attributeName + * @param string $attributeName * * @return Twig */ @@ -80,7 +80,7 @@ public static function fromRequest(ServerRequestInterface $request, string $attr } /** - * @param string|string[] $path Path(s) to templates directory + * @param string|string[] $path Path(s) to templates directory * @param array $settings Twig environment settings * * @throws LoaderError When the template cannot be found @@ -104,7 +104,7 @@ public static function create($path, array $settings = []): self } /** - * @param LoaderInterface $loader Twig loader + * @param LoaderInterface $loader Twig loader * @param array $settings Twig environment settings */ public function __construct(LoaderInterface $loader, array $settings = []) @@ -138,8 +138,8 @@ public function addRuntimeLoader(RuntimeLoaderInterface $runtimeLoader): void /** * Fetch rendered template * - * @param string $template Template pathname relative to templates directory - * @param array $data Associative array of template variables + * @param string $template Template pathname relative to templates directory + * @param array $data Associative array of template variables * * @throws LoaderError When the template cannot be found * @throws SyntaxError When an error occurred during compilation @@ -157,9 +157,9 @@ public function fetch(string $template, array $data = []): string /** * Fetch rendered block * - * @param string $template Template pathname relative to templates directory - * @param string $block Name of the block within the template - * @param array $data Associative array of template variables + * @param string $template Template pathname relative to templates directory + * @param string $block Name of the block within the template + * @param array $data Associative array of template variables * * @throws Throwable When an error occurred during rendering * @throws LoaderError When the template cannot be found @@ -177,8 +177,8 @@ public function fetchBlock(string $template, string $block, array $data = []): s /** * Fetch rendered string * - * @param string $string String - * @param array $data Associative array of template variables + * @param string $string String + * @param array $data Associative array of template variables * * @throws LoaderError When the template cannot be found * @throws SyntaxError When an error occurred during compilation @@ -195,9 +195,9 @@ public function fetchFromString(string $string = '', array $data = []): string /** * Output rendered template * - * @param ResponseInterface $response - * @param string $template Template pathname relative to templates directory - * @param array $data Associative array of template variables + * @param ResponseInterface $response + * @param string $template Template pathname relative to templates directory + * @param array $data Associative array of template variables * * @throws LoaderError When the template cannot be found * @throws SyntaxError When an error occurred during compilation @@ -235,7 +235,7 @@ public function getEnvironment(): Environment /** * Does this collection have a given key? * - * @param string $key The data key + * @param string $key The data key * * @return bool */ @@ -263,8 +263,8 @@ public function offsetGet($key) /** * Set collection item * - * @param string $key The data key - * @param mixed $value The data value + * @param string $key The data key + * @param mixed $value The data value */ public function offsetSet($key, $value): void { diff --git a/src/TwigMiddleware.php b/src/TwigMiddleware.php index 01e8392..1f98374 100644 --- a/src/TwigMiddleware.php +++ b/src/TwigMiddleware.php @@ -10,12 +10,14 @@ namespace Slim\Views; +use Psr\Container\ContainerInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; use RuntimeException; use Slim\App; +use Slim\Interfaces\RouteCollectorProxyInterface; use Slim\Interfaces\RouteParserInterface; class TwigMiddleware implements MiddlewareInterface @@ -29,7 +31,7 @@ class TwigMiddleware implements MiddlewareInterface protected ?string $attributeName; /** - * @param App $app + * @param App $app * @param string $containerKey * * @return TwigMiddleware @@ -61,8 +63,8 @@ public static function createFromContainer(App $app, string $containerKey = 'vie } /** - * @param App $app - * @param Twig $twig + * @param App $app + * @param Twig $twig * @param string $attributeName * * @return TwigMiddleware @@ -78,10 +80,10 @@ public static function create(App $app, Twig $twig, string $attributeName = 'vie } /** - * @param Twig $twig + * @param Twig $twig * @param RouteParserInterface $routeParser - * @param string $basePath - * @param string|null $attributeName + * @param string $basePath + * @param string|null $attributeName */ public function __construct( Twig $twig, @@ -98,7 +100,7 @@ public function __construct( /** * Process an incoming server request. * - * @param ServerRequestInterface $request + * @param ServerRequestInterface $request * @param RequestHandlerInterface $handler * * @return ResponseInterface diff --git a/src/TwigRuntimeExtension.php b/src/TwigRuntimeExtension.php index 13926c8..15de973 100644 --- a/src/TwigRuntimeExtension.php +++ b/src/TwigRuntimeExtension.php @@ -23,8 +23,8 @@ class TwigRuntimeExtension /** * @param RouteParserInterface $routeParser Route parser - * @param UriInterface $uri Uri - * @param string $basePath Base path + * @param UriInterface $uri Uri + * @param string $basePath Base path */ public function __construct(RouteParserInterface $routeParser, UriInterface $uri, string $basePath = '') { @@ -36,8 +36,8 @@ public function __construct(RouteParserInterface $routeParser, UriInterface $uri /** * Get the url for a named route * - * @param string $routeName Route name - * @param array $data Route placeholders + * @param string $routeName Route name + * @param array $data Route placeholders * @param array $queryParams Query parameters * * @return string @@ -50,8 +50,8 @@ public function urlFor(string $routeName, array $data = [], array $queryParams = /** * Get the full url for a named route * - * @param string $routeName Route name - * @param array $data Route placeholders + * @param string $routeName Route name + * @param array $data Route placeholders * @param array $queryParams Query parameters * * @return string @@ -62,8 +62,8 @@ public function fullUrlFor(string $routeName, array $data = [], array $queryPara } /** - * @param string $routeName Route name - * @param array $data Route placeholders + * @param string $routeName Route name + * @param array $data Route placeholders * * @return bool */ diff --git a/src/TwigRuntimeLoader.php b/src/TwigRuntimeLoader.php index 2ac9c08..0f195ed 100644 --- a/src/TwigRuntimeLoader.php +++ b/src/TwigRuntimeLoader.php @@ -26,8 +26,8 @@ class TwigRuntimeLoader implements RuntimeLoaderInterface * TwigRuntimeLoader constructor. * * @param RouteParserInterface $routeParser - * @param UriInterface $uri - * @param string $basePath + * @param UriInterface $uri + * @param string $basePath */ public function __construct(RouteParserInterface $routeParser, UriInterface $uri, string $basePath = '') { diff --git a/tests/TwigMiddlewareTest.php b/tests/TwigMiddlewareTest.php index 94c3436..0a6c2f8 100644 --- a/tests/TwigMiddlewareTest.php +++ b/tests/TwigMiddlewareTest.php @@ -33,7 +33,7 @@ class TwigMiddlewareTest extends TestCase * Create a twig prophecy given a uri prophecy and a base path. * * @param ObjectProphecy $uriProphecy - * @param string $basePath + * @param string $basePath * * @return ObjectProphecy&Twig */ diff --git a/tests/TwigRuntimeExtensionTest.php b/tests/TwigRuntimeExtensionTest.php index 9219e47..b68660a 100644 --- a/tests/TwigRuntimeExtensionTest.php +++ b/tests/TwigRuntimeExtensionTest.php @@ -66,7 +66,7 @@ protected function mapRouteCollectorRoute( return $route; } - public function isCurrentUrlProvider(): array + public static function isCurrentUrlProvider(): array { return [ ['/hello/{name}', ['name' => 'world'], '/hello/world', '/base-path', true], @@ -109,7 +109,7 @@ public function testIsCurrentUrl(string $pattern, array $data, string $path, ?st $this->assertEquals($expected, $result); } - public function currentUrlProvider(): array + public static function currentUrlProvider(): array { return [ ['/hello/{name}', 'http://example.com/hello/world?a=b', '', true], @@ -164,7 +164,7 @@ public function testCurrentUrl(string $pattern, string $url, string $basePath, b $this->assertEquals($expected, $result); } - public function urlForProvider(): array + public static function urlForProvider(): array { return [ ['/hello/{name}', ['name' => 'world'], [], '', '/hello/world'], @@ -204,7 +204,7 @@ public function testUrlFor( $this->assertEquals($expectedUrl, $extension->urlFor($routeName, $routeData, $queryParams)); } - public function fullUrlForProvider(): array + public static function fullUrlForProvider(): array { return [ ['/hello/{name}', ['name' => 'world'], [], '', 'http://localhost/hello/world'],