Skip to content

Commit

Permalink
Run checks every monday (#284)
Browse files Browse the repository at this point in the history
* Run checks every monday

* Fix code style

* Add properties types

* fix cs
  • Loading branch information
funivan authored Apr 19, 2023
1 parent 2553e41 commit 881a7c5
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 86 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: CI

on:
schedule:
- cron: '00 1 * * 1' # At 01:00 on Mondays.
push:
branches:
- master
Expand Down Expand Up @@ -38,8 +40,8 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist --dev

# - name: Run fixer
# run: ./vendor/bin/php-cs-fixer fix --config=.php_cs_config.php -v --dry-run --stop-on-violation
- name: Run fixer
run: ./vendor/bin/php-cs-fixer fix . -v --dry-run --stop-on-violation

- name: Run tests
run: ./vendor/bin/phpunit
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
build
vendor
composer.lock
.phpunit.result.cache
.php-cs-fixer.cache

# Share ide configuration
!.idea/inspectionProfiles/*
Expand Down
83 changes: 36 additions & 47 deletions .php_cs_config.php
Original file line number Diff line number Diff line change
@@ -1,49 +1,38 @@
<?php
$config = PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'psr4' => true,
'phpdoc_indent' => true,
'array_syntax' => ['syntax' => 'short'],
'blank_line_before_statement' => false,
'strict_comparison' => true,
'strict_param' => true,
'no_null_property_initialization' => true,
'yoda_style' => false,
'ordered_imports' => ['sortAlgorithm' => 'alpha'],
'ordered_class_elements' => [
'use_trait',
'constant_public',
'constant_protected',
'constant_private',
'property_public',
'property_protected',
'property_private',
'construct',
'destruct',
'magic',
'phpunit',
'method_public',
'method_protected',
'method_private'
],
])
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__.'/src')
->in(__DIR__.'/tests')
)

$finder = PhpCsFixer\Finder::create()
->in(__DIR__.'/src')
->in(__DIR__ . '/tests')
;
// special handling of fabbot.io service if it's using too old PHP CS Fixer version
try {
PhpCsFixer\FixerFactory::create()
->registerBuiltInFixers()
->registerCustomFixers($config->getCustomFixers())
->useRuleSet(new PhpCsFixer\RuleSet($config->getRules()));
} catch (PhpCsFixer\ConfigurationException\InvalidConfigurationException $e) {
$config->setRules([]);
} catch (UnexpectedValueException $e) {
$config->setRules([]);
}
return $config;

return PhpCsFixer\Config::create()
->setFinder($finder)
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'psr4' => true,
'phpdoc_indent' => true,
'array_syntax' => ['syntax' => 'short'],
'blank_line_before_statement' => false,
'strict_comparison' => true,
'strict_param' => true,
'no_null_property_initialization' => true,
'yoda_style' => false,
'ordered_imports' => ['sortAlgorithm' => 'alpha'],
'ordered_class_elements' => [
'use_trait',
'constant_public',
'constant_protected',
'constant_private',
'property_public',
'property_protected',
'property_private',
'construct',
'destruct',
'magic',
'phpunit',
'method_public',
'method_protected',
'method_private'
],
]);
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"ext-dom": "*"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"friendsofphp/php-cs-fixer": "^3.16",
"phpunit/phpunit": "^9.5.2"
},
"autoload": {
Expand Down
1 change: 0 additions & 1 deletion src/Collection/ElementCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*/
class ElementCollection implements \IteratorAggregate, \Countable
{

/**
* @var Element[]
*/
Expand Down
1 change: 0 additions & 1 deletion src/Collection/Filters/StringFilter/RegexStringFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
class RegexStringFilter implements StringFilterInterface
{

/**
* @var string
*/
Expand Down
1 change: 0 additions & 1 deletion src/Collection/Modify/StringModify/RegexReplace.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
class RegexReplace implements StringModifyInterface
{

/**
* @var string
*/
Expand Down
1 change: 0 additions & 1 deletion src/Collection/ObjectCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*/
class ObjectCollection implements \IteratorAggregate, \Countable
{

/**
* @var ElementFinderInterface[]
*/
Expand Down
1 change: 0 additions & 1 deletion src/Collection/StringCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
class StringCollection implements \IteratorAggregate, \Countable
{

/**
* @var string[]
*/
Expand Down
1 change: 1 addition & 0 deletions src/DomNodeListAction/DomNodeListActionInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Xparse\ElementFinder\DomNodeListAction;
Expand Down
43 changes: 15 additions & 28 deletions src/ElementFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/
class ElementFinder implements ElementFinderInterface
{

/**
* Html document type
*
Expand All @@ -35,32 +34,17 @@ class ElementFinder implements ElementFinderInterface
*/
public const DOCUMENT_XML = 1;

/**
* Current document type
*
* @var int
*/
private $type;
private int $type;
private \DOMDocument $dom;

/**
* @var \DOMDocument
*/
private $dom;
private \DomXPath $xpath;

/**
* @var \DomXPath
*/
private $xpath;

/**
* @var ExpressionTranslatorInterface
*/
private $expressionTranslator;
private ExpressionTranslatorInterface $expressionTranslator;

/**
* @var array
* @var \LibXMLError[]
*/
private $loadErrors = [];
private array $loadErrors = [];


/**
Expand All @@ -69,8 +53,11 @@ class ElementFinder implements ElementFinderInterface
*
* @throws \Exception
*/
public function __construct(string $data, int $documentType = null, ExpressionTranslatorInterface $translator = null)
{
public function __construct(
string $data,
int $documentType = null,
ExpressionTranslatorInterface $translator = null
) {
$this->dom = new \DomDocument();
$this->expressionTranslator = $translator ?? new XpathExpression();
$this->dom->registerNodeClass(\DOMElement::class, Element::class);
Expand Down Expand Up @@ -180,12 +167,12 @@ final public function object(string $expression, bool $outerHtml = false): Objec
foreach ($items as $node) {
assert($node instanceof \DOMElement);
$html = $outerHtml
? NodeHelper::getOuterContent($node)
: NodeHelper::getInnerContent($node);
? NodeHelper::getOuterContent($node)
: NodeHelper::getInnerContent($node);
if (trim($html) === '') {
$html = '<html data-document-is-empty></html>';
}
if ($this->type === static::DOCUMENT_XML and strpos($html, '<?xml') === false) {
if ($this->type === static::DOCUMENT_XML and !str_contains($html, '<?xml')) {
$html = '<root>' . $html . '</root>';
}
$result[] = new ElementFinder($html, $type, $this->expressionTranslator);
Expand Down Expand Up @@ -225,7 +212,7 @@ private function setData(string $data): self
$internalErrors = libxml_use_internal_errors(true);
$disableEntities = false;
if (\LIBXML_VERSION < 20900) {
$disableEntities = libxml_disable_entity_loader(true);
$disableEntities = libxml_disable_entity_loader();
}

if (static::DOCUMENT_HTML === $this->type) {
Expand Down
1 change: 0 additions & 1 deletion src/ElementFinder/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
class Element extends \DOMElement
{

/**
* @return array Array<String, String>
*/
Expand Down
1 change: 0 additions & 1 deletion src/ElementFinderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
interface ElementFinderInterface
{

/**
* @throws \Exception
*/
Expand Down
1 change: 0 additions & 1 deletion src/Helper/FormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*/
class FormHelper
{

/**
* @var ElementFinderInterface
*/
Expand Down

0 comments on commit 881a7c5

Please sign in to comment.