diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 1ec8cb4..64c9ff3 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -6,16 +6,15 @@ on: jobs: tests: - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 strategy: matrix: - php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] + php: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5'] name: PHP ${{ matrix.php }} steps: - - uses: actions/checkout@v3 - # required for "git tag" presence for MonorepoBuilder split and ChangelogLinker git tags resolver; default is 1 - - run: git fetch --depth=100000 origin - # see https://github.com/shivammathur/setup-php + - uses: actions/checkout@v6 + with: + fetch-depth: 5 - uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} @@ -26,14 +25,14 @@ jobs: tests_lowest_dependencies: name: Lowest dependencies - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@v3 - - run: git fetch --depth=100000 origin - # see https://github.com/shivammathur/setup-php + - uses: actions/checkout@v6 + with: + fetch-depth: 5 - uses: shivammathur/setup-php@v2 with: - php-version: '7.1' + php-version: '7.4' extensions: xml coverage: none - run: composer update --no-progress --prefer-lowest @@ -41,14 +40,14 @@ jobs: test_coverage: name: Coverage - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@v3 - - run: git fetch --depth=100000 origin - # see https://github.com/shivammathur/setup-php + - uses: actions/checkout@v6 + with: + fetch-depth: 5 - uses: shivammathur/setup-php@v2 with: - php-version: '7.1' + php-version: '7.4' extensions: xml, xdebug coverage: xdebug - run: composer install --no-progress @@ -59,13 +58,14 @@ jobs: php-cs-fixer: name: PHP CS Fixer - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@v3 - # see https://github.com/shivammathur/setup-php + - uses: actions/checkout@v6 + with: + fetch-depth: 5 - uses: shivammathur/setup-php@v2 with: - php-version: '8.2' + php-version: '8.4' extensions: xml coverage: none - run: composer install --no-progress @@ -73,12 +73,14 @@ jobs: phpstan: name: PHPStan - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v6 + with: + fetch-depth: 5 - uses: shivammathur/setup-php@v2 with: - php-version: '8.2' + php-version: '8.4' coverage: none - run: composer install --no-progress - run: composer phpstan \ No newline at end of file diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 750f3ae..d4a1a25 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -1,33 +1,36 @@ exclude('vendor') ->in(__DIR__) ; -$config = new PhpCsFixer\Config(); -return $config->setRules([ - '@PSR12' => true, - '@PSR12:risky' => true, - '@PhpCsFixer' => true, - '@PhpCsFixer:risky' => true, - '@PHP71Migration' => true, - '@PHP71Migration:risky' => true, - 'array_syntax' => ['syntax' => 'short'], - 'php_unit_test_class_requires_covers' => false, - 'backtick_to_shell_exec' => true, - 'blank_line_before_statement' => [ - 'statements' => ['declare', 'return', 'case'], - ], - 'comment_to_phpdoc' => false, - 'declare_equal_normalize' => ['space' => 'single'], - 'global_namespace_import' => true, - 'linebreak_after_opening_tag' => true, - 'native_function_invocation' => false, - 'no_unset_on_property' => false, - 'php_unit_test_case_static_method_calls' => ['call_type' => 'self'], - 'phpdoc_to_comment' => false, - 'self_static_accessor' => true, -]) - ->setFinder($finder) - ; \ No newline at end of file +$config = new Config(); +return $config + ->setParallelConfig(ParallelConfigFactory::detect()) + ->setRules([ + '@auto' => true, + '@auto:risky' => true, + '@PhpCsFixer' => true, + '@PhpCsFixer:risky' => true, + 'array_syntax' => ['syntax' => 'short'], + 'php_unit_test_class_requires_covers' => false, + 'backtick_to_shell_exec' => true, + 'blank_line_before_statement' => [ + 'statements' => ['declare', 'return', 'case'], + ], + 'comment_to_phpdoc' => false, + 'declare_equal_normalize' => ['space' => 'single'], + 'global_namespace_import' => true, + 'linebreak_after_opening_tag' => true, + 'native_function_invocation' => false, + 'no_unset_on_property' => false, + 'php_unit_test_case_static_method_calls' => ['call_type' => 'self'], + 'phpdoc_to_comment' => false, + 'self_static_accessor' => true, + ]) + ->setFinder($finder); diff --git a/composer.json b/composer.json index e39ee9c..8b1396c 100644 --- a/composer.json +++ b/composer.json @@ -16,20 +16,20 @@ } ], "require": { - "php": "^7.1 || ^8.0", + "php": "^7.4 || ^8.0", "ext-dom": "*", "ext-filter": "*", "ext-libxml": "*", "ext-simplexml": "*", - "webmozart/assert": "^1.5" + "webmozart/assert": "^1.5 || ^2.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.0", - "phpstan/phpstan": "^1.0", - "phpstan/phpstan-phpunit": "^1.0", - "phpstan/phpstan-strict-rules": "^1.0", - "phpstan/phpstan-webmozart-assert": "^1.0", - "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0" + "friendsofphp/php-cs-fixer": "^3.92", + "phpstan/phpstan": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", + "phpstan/phpstan-strict-rules": "^2.0", + "phpstan/phpstan-webmozart-assert": "^2.0", + "phpunit/phpunit": "^9.1 || ^10.0" }, "config": { "sort-packages": true diff --git a/example/feed.php b/example/feed.php index 59915bf..4021daf 100644 --- a/example/feed.php +++ b/example/feed.php @@ -5,7 +5,7 @@ use AtomGenerator\Entry; use AtomGenerator\Feed; -include_once 'vendor/autoload.php'; +include_once __DIR__.'/../vendor/autoload.php'; $entry = new Entry(); $entry->setTitle('Post', 'text'); diff --git a/phpunit.xml b/phpunit.xml index 01dcc3a..4d0e0cc 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -3,12 +3,12 @@ xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true"> - + src tests - + tests diff --git a/src/AbstractElement.php b/src/AbstractElement.php index 31ddbd2..f06334a 100644 --- a/src/AbstractElement.php +++ b/src/AbstractElement.php @@ -12,35 +12,29 @@ abstract class AbstractElement { - /** @var string */ - protected $id; + protected string $id; - /** @var string */ - protected $title; + protected string $title; - /** @var null|string */ - protected $titleType; + protected ?string $titleType = null; - /** @var DateTimeInterface */ - protected $updatedDateTime; + protected DateTimeInterface $updatedDateTime; - /** @var null|string */ - protected $rights; + protected ?string $rights = null; - /** @var null|string */ - protected $rightsType; + protected ?string $rightsType = null; /** @var string[][] */ - protected $authors = []; + protected array $authors = []; /** @var string[][] */ - protected $contributors = []; + protected array $contributors = []; /** @var string[][] */ - protected $categories = []; + protected array $categories = []; /** @var string[][] */ - protected $links = []; + protected array $links = []; /** * AbstractElement constructor. diff --git a/src/Entry.php b/src/Entry.php index 9ef23d0..680c42b 100644 --- a/src/Entry.php +++ b/src/Entry.php @@ -10,26 +10,19 @@ class Entry extends AbstractElement { - /** @var null|string */ - protected $summary; + protected ?string $summary = null; - /** @var null|string */ - protected $summaryType; + protected ?string $summaryType = null; - /** @var null|string */ - protected $content; + protected ?string $content = null; - /** @var null|string */ - protected $contentType; + protected ?string $contentType = null; - /** @var null|string */ - protected $contentSrc; + protected ?string $contentSrc = null; - /** @var null|DateTimeInterface */ - protected $publishedDateTime; + protected ?DateTimeInterface $publishedDateTime = null; - /** @var null|Feed */ - protected $source; + protected ?Feed $source = null; public function setSummary(?string $summary, ?string $type = null): void { diff --git a/src/Feed.php b/src/Feed.php index abd0c70..532d018 100644 --- a/src/Feed.php +++ b/src/Feed.php @@ -5,6 +5,7 @@ namespace AtomGenerator; use DOMDocument; +use Exception; use LibXMLError; use SimpleXMLElement; use Webmozart\Assert\Assert; @@ -12,38 +13,30 @@ class Feed extends AbstractElement { /** @var Entry[] */ - protected $entries = []; + protected array $entries = []; - /** @var bool */ - protected $prettify = false; + protected bool $prettify = false; - /** @var null|string */ - protected $language; + protected ?string $language = null; - /** @var null|string */ - protected $subtitle; + protected ?string $subtitle = null; - /** @var null|string */ - protected $icon; + protected ?string $icon = null; - /** @var null|string */ - protected $logo; + protected ?string $logo = null; - /** @var null|string */ - protected $generator; + protected ?string $generator = null; - /** @var null|string */ - protected $generatorVersion; + protected ?string $generatorVersion = null; - /** @var null|string */ - protected $generatorUri; + protected ?string $generatorUri = null; /** * @var array[] * * @phpstan-var array */ - protected $customElements = []; + protected array $customElements = []; /** * Feed constructor. @@ -174,6 +167,9 @@ public function addChildrenTo(SimpleXMLElement $parent): void } } + /** + * @throws Exception + */ public function getSimpleXML(): SimpleXMLElement { $attributes = []; diff --git a/tests/FeedTest.php b/tests/FeedTest.php index 422d3cc..9f0e25d 100644 --- a/tests/FeedTest.php +++ b/tests/FeedTest.php @@ -17,12 +17,15 @@ final class FeedTest extends TestCase { protected const TEST_FEED_XML_PATH_1 = __DIR__.'/feed_1.xml'; + protected const TEST_FEED_XML_PATH_2 = __DIR__.'/feed_2.xml'; + protected const TEST_FEED_XML_PATH_3 = __DIR__.'/feed_3.xml'; + protected const TEST_FEED_XML_PATH_4 = __DIR__.'/feed_4.xml'; /** @var bool reset file contents */ - protected static $reset = false; + protected static bool $reset = false; public function testFeedCreation1(): void { @@ -67,7 +70,7 @@ public function testFeedCreation1(): void } $valid = Feed::validate($feed->getDocument(), $errors); - self::assertTrue($valid, self::formatXmlErrors($errors)); + self::assertTrue($valid, self::formatXmlErrors($errors ?? [])); $xml = $feed->saveXML(); assert(false !== $xml); @@ -99,7 +102,7 @@ public function testFeedCreation2(): void } $valid = Feed::validate($feed->getDocument(), $errors); - self::assertTrue($valid, self::formatXmlErrors($errors)); + self::assertTrue($valid, self::formatXmlErrors($errors ?? [])); $xml = $feed->saveXML(); assert(false !== $xml); @@ -127,7 +130,7 @@ public function testFeedCreation3(): void } $valid = Feed::validate($feed->getDocument(), $errors); - self::assertTrue($valid, self::formatXmlErrors($errors)); + self::assertTrue($valid, self::formatXmlErrors($errors ?? [])); $xml = $feed->saveXML(); assert(false !== $xml); @@ -161,7 +164,7 @@ public function testFeedCreation4(): void } $valid = Feed::validate($feed->getDocument(), $errors); - self::assertTrue($valid, self::formatXmlErrors($errors)); + self::assertTrue($valid, self::formatXmlErrors($errors ?? [])); $xml = $feed->saveXML(); assert(false !== $xml);