Skip to content

Commit

Permalink
chore/refactor: Install PHPStan and remove Scrutinizer
Browse files Browse the repository at this point in the history
  • Loading branch information
yusufkandemir committed Apr 3, 2022
1 parent 0aea612 commit 70fc06a
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 47 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/analyze-quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Analyze Code Quality

on:
push:
paths:
- "**.php"

jobs:
analyze:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.1"
coverage: none

- name: Install dependencies
run: composer update --prefer-dist --no-interaction

- name: Run the code quality analyzer
run: ./vendor/bin/phpstan
31 changes: 0 additions & 31 deletions .scrutinizer.yml

This file was deleted.

11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
[![Software License][ico-license]](LICENSE.md)
[![PHP Version Support][ico-version]]([link-version])
[![Tests][ico-tests]][link-tests]
[![Coverage Status][ico-scrutinizer]][link-scrutinizer]
[![Quality Score][ico-code-quality]][link-code-quality]
[![Quality Checks][ico-code-quality]][link-code-quality]
[![Total Downloads][ico-downloads]][link-downloads]

This package aims to implement [W3C Microdata to JSON Specification](https://www.w3.org/TR/microdata/#json).
Expand Down Expand Up @@ -84,16 +83,14 @@ The MIT License (MIT). Please see [License File](LICENSE.md) for more informatio
[ico-version]: https://img.shields.io/packagist/v/yusufkandemir/microdata-parser.svg?style=flat-square
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[ico-version]: https://img.shields.io/packagist/php-v/yusufkandemir/microdata-parser?style=flat-square
[ico-tests]: https://img.shields.io/github/workflow/status/yusufkandemir/microdata-parser/run-tests?style=flat-square&label=Tests
[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/yusufkandemir/microdata-parser.svg?style=flat-square
[ico-code-quality]: https://img.shields.io/scrutinizer/g/yusufkandemir/microdata-parser.svg?style=flat-square
[ico-tests]: https://img.shields.io/github/workflow/status/yusufkandemir/microdata-parser/run-tests?style=flat-square&label=tests
[ico-code-quality]: https://img.shields.io/github/workflow/status/yusufkandemir/microdata-parser/analyze-quality?style=flat-square&label=quality
[ico-downloads]: https://img.shields.io/packagist/dt/yusufkandemir/microdata-parser.svg?style=flat-square

[link-packagist]: https://packagist.org/packages/yusufkandemir/microdata-parser
[link-version]: https://packagist.org/packages/yusufkandemir/microdata-parser
[link-tests]: https://github.com/yusufkandemir/microdata-parser/actions/workflows/run-tests.yml
[link-scrutinizer]: https://scrutinizer-ci.com/g/yusufkandemir/microdata-parser/code-structure
[link-code-quality]: https://scrutinizer-ci.com/g/yusufkandemir/microdata-parser
[link-code-quality]: https://github.com/yusufkandemir/microdata-parser/actions/workflows/analyze-quality.yml
[link-downloads]: https://packagist.org/packages/yusufkandemir/microdata-parser
[link-author]: https://github.com/yusufkandemir
[link-contributors]: ../../contributors
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
}
],
"scripts": {
"analyze": "phpstan",
"test": "pest",
"lint": "php-cs-fixer fix --dry-run --verbose",
"lint:fix": "php-cs-fixer fix"
Expand All @@ -30,7 +31,8 @@
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.8",
"pestphp/pest": "^1.21"
"pestphp/pest": "^1.21",
"phpstan/phpstan": "^1.5"
},
"suggest": {
"ext-json": "Needed to convert results to JSON"
Expand Down
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: 6
paths:
- src
tmpDir: build/phpstan
2 changes: 1 addition & 1 deletion src/MicrodataDOMDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MicrodataDOMDocument extends DOMDocument
*
* @see https://www.w3.org/TR/2018/WD-microdata-20180426/#dfn-top-level-microdata-item
*
* @return \DOMNodeList List of top level items as elements
* @return \DOMNodeList<MicrodataDOMElement> List of top level items as elements
*/
public function getItems(): \DOMNodeList
{
Expand Down
7 changes: 4 additions & 3 deletions src/MicrodataDOMElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected function getChildElementNodes(): array
{
$childNodes = [];

/** @var \DOMNode $childNode */
/** @var self $childNode */
foreach ($this->childNodes as $childNode) {
if ($childNode->nodeType === \XML_ELEMENT_NODE) {
$childNodes[] = $childNode;
Expand Down Expand Up @@ -193,8 +193,9 @@ protected function getReferenceNodes(): array
foreach ($tokens as $token) {
$references = $this->ownerDocument->xpath->query('//*[@id="' . $token . '"]');

/** @var self $first */
if ($first = $references->item(0)) {
/** @var self|null $first */
$first = $references->item(0);
if ($first) {
$referenceNodes[] = $first;
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/MicrodataParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public function __construct(MicrodataDOMDocument $dom, callable $absoluteUriHand

/**
* Extracts and converts microdata to associative array.
*
* @return mixed[]
*/
public function toArray(): array
{
Expand Down Expand Up @@ -128,17 +130,15 @@ protected function getObject(MicrodataDOMElement $item, array $memory = []): std
/**
* Set absolute uri handler.
*/
public function setAbsoluteUriHandler(callable $handler)
public function setAbsoluteUriHandler(callable $handler): void
{
$this->absoluteUriHandler = $handler;
}

/**
* Check if the given parameter is a MicrodataDOMElement and has itemscope attribute.
*
* @param $element
*/
protected function isItem($element): bool
protected function isItem(mixed $element): bool
{
return $element instanceof MicrodataDOMElement && $element->hasAttribute('itemscope');
}
Expand Down

0 comments on commit 70fc06a

Please sign in to comment.