diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 7a0d019f..f712746c 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -15,7 +15,14 @@ "mehedidracula.php-namespace-resolver" ], "settings": { - "php.validate.executablePath": "/usr/local/bin/php" + "php.validate.executablePath": "/usr/local/bin/php", + "terminal.integrated.defaultProfile.linux": "bash", + "terminal.integrated.profiles.linux": { + "bash": { + "path": "/bin/bash", + "args": ["-l"] + } + } } } }, diff --git a/.github/workflows/phpstan-baseline.yml b/.github/workflows/phpstan-baseline.yml new file mode 100644 index 00000000..0dc2bcff --- /dev/null +++ b/.github/workflows/phpstan-baseline.yml @@ -0,0 +1,41 @@ +name: PHPStan Baseline Check + +on: + pull_request: + branches: [ main, master ] + paths: + - 'src/**/*.php' + +jobs: + phpstan: + runs-on: ubuntu-latest + + strategy: + matrix: + php-version: ['8.4'] + fail-fast: false + + steps: + - uses: actions/checkout@v5 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + extensions: dom, json, libxml + coverage: xdebug + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v4 + with: + path: vendor + key: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php-${{ matrix.php-version }}- + + - name: Install dependencies + run: composer install --prefer-dist --no-progress + + - name: Run PHPStan with baseline + run: vendor/bin/phpstan analyse --error-format=github diff --git a/docs/codecontributions.md b/docs/codecontributions.md new file mode 100644 index 00000000..795fe824 --- /dev/null +++ b/docs/codecontributions.md @@ -0,0 +1,63 @@ +# Code Quality + +This project uses PHPStan for static analysis and Rector for automated code refactoring to maintain high code quality standards. + +## PHPStan - Static Analysis + +PHPStan analyzes the code for potential issues and type safety problems. The configuration is stored in `phpstan.neon.dist`. + +### Generate a new baseline +When introducing PHPStan to legacy code or after major refactoring, you can create a baseline to suppress existing errors: +```bash +vendor/bin/phpstan analyse --generate-baseline +``` + +### Run analysis +To analyze the codebase and find issues: +```bash +vendor/bin/phpstan analyse +``` + +### Configuration +- Configuration file: `phpstan.neon.dist` +- Current analysis level: 5 +- Baseline file: `phpstan-baseline.neon` (suppresses known issues) + +## Rector - Automated Refactoring + +Rector automatically modernizes PHP code and applies coding standards. The configuration is stored in `rector.php`. + +### Preview changes (recommended first step) +Run a dry-run to see what changes Rector would make without actually modifying files: +```bash +vendor/bin/rector process --dry-run +``` + +### Apply changes +Apply the refactoring rules to actually modify the code: +```bash +vendor/bin/rector process +``` + +### Debug mode +To see detailed information about what Rector is doing: +```bash +vendor/bin/rector process --dry-run --debug +``` + +### Finding new rules +To discover additional Rector rules for your project, visit: https://getrector.com/find-rule + +## Workflow + +1. **Before making changes**: Run `vendor/bin/phpstan analyse` to check current code quality +2. **Use Rector for improvements**: Run `vendor/bin/rector process --dry-run` to preview automated fixes +3. **Apply safe changes**: Run `vendor/bin/rector process` to apply the changes +4. **Verify with tests**: Run `make test` to ensure changes don't break functionality +5. **Final analysis**: Run `vendor/bin/phpstan analyse` to confirm improvements + +## CI/CD Integration + +Both PHPStan and Rector are integrated into the CI pipeline to ensure: +- No new PHPStan errors are introduced (beyond the baseline) +- Code follows modern PHP practices through Rector \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index e5cc63cb..02dd78c5 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1,3 +1,7 @@ site_name: feed-io Documentation theme: name: material + +nav: + - Home: index.md + - Code Quality: codecontributions.md diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 00000000..c968ee54 --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,49 @@ +parameters: + ignoreErrors: + - + message: '#^Call to an undefined method FeedIo\\Feed\\ItemInterface\:\:setHostInContent\(\)\.$#' + identifier: method.notFound + count: 1 + path: src/FeedIo/Feed.php + + - + message: '#^Call to an undefined method FeedIo\\Feed\\ItemInterface\:\:setLinkForAnalysis\(\)\.$#' + identifier: method.notFound + count: 1 + path: src/FeedIo/Parser/XmlParser.php + + - + message: '#^Deprecated in PHP 8\.0\: Required parameter \$url follows optional parameter \$modifiedSince\.$#' + identifier: parameter.requiredAfterOptional + count: 1 + path: src/FeedIo/Reader/Result.php + + - + message: '#^Deprecated in PHP 8\.1\: Required parameter \$response follows optional parameter \$modifiedSince\.$#' + identifier: parameter.requiredAfterOptional + count: 1 + path: src/FeedIo/Reader/Result.php + + - + message: '#^Offset float on list in isset\(\) does not exist\.$#' + identifier: isset.offset + count: 1 + path: src/FeedIo/Reader/Result/UpdateStats.php + + - + message: '#^Call to an undefined method FeedIo\\Feed\\NodeInterface\:\:getHostFromLink\(\)\.$#' + identifier: method.notFound + count: 1 + path: src/FeedIo/Rule/Atom/Link.php + + - + message: '#^Call to an undefined method FeedIo\\Feed\\NodeInterface\:\:getHostFromLink\(\)\.$#' + identifier: method.notFound + count: 1 + path: src/FeedIo/Rule/Link.php + + - + message: '#^PHPDoc tag @var with type FeedIo\\Reader\\FixerAbstract is not subtype of native type FeedIo\\Reader\\Fixer\\HttpLastModified\|FeedIo\\Reader\\Fixer\\PublicId\.$#' + identifier: varTag.nativeType + count: 1 + path: src/FeedIo/Specification.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 4d08f439..f00155ba 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,3 +1,6 @@ +includes: + - phpstan-baseline.neon + parameters: errorFormat: table level: 5 diff --git a/src/FeedIo/Adapter/ClientInterface.php b/src/FeedIo/Adapter/ClientInterface.php index 235e0cdd..97ae6538 100644 --- a/src/FeedIo/Adapter/ClientInterface.php +++ b/src/FeedIo/Adapter/ClientInterface.php @@ -21,5 +21,5 @@ interface ClientInterface * @throws \FeedIo\Adapter\ServerErrorException * @return \FeedIo\Adapter\ResponseInterface */ - public function getResponse(string $url, DateTime $modifiedSince = null): ResponseInterface; + public function getResponse(string $url, ?DateTime $modifiedSince = null): ResponseInterface; } diff --git a/src/FeedIo/Adapter/FileSystem/Client.php b/src/FeedIo/Adapter/FileSystem/Client.php index 5709a2fd..19b6ddba 100644 --- a/src/FeedIo/Adapter/FileSystem/Client.php +++ b/src/FeedIo/Adapter/FileSystem/Client.php @@ -20,7 +20,7 @@ class Client implements ClientInterface * @return \FeedIo\Adapter\ResponseInterface *@throws \FeedIo\Adapter\NotFoundException */ - public function getResponse(string $path, DateTime $modifiedSince = null): ResponseInterface + public function getResponse(string $path, ?DateTime $modifiedSince = null): ResponseInterface { if (file_exists($path)) { return new Response( diff --git a/src/FeedIo/Adapter/Http/Client.php b/src/FeedIo/Adapter/Http/Client.php index 86457f25..776fbd28 100644 --- a/src/FeedIo/Adapter/Http/Client.php +++ b/src/FeedIo/Adapter/Http/Client.php @@ -25,7 +25,7 @@ public function __construct(private readonly PsrClientInterface $client) * @return ResponseInterface * @throws ClientExceptionInterface */ - public function getResponse(string $url, DateTime $modifiedSince = null): ResponseInterface + public function getResponse(string $url, ?DateTime $modifiedSince = null): ResponseInterface { if ($modifiedSince) { $headResponse = $this->request('HEAD', $url, $modifiedSince); @@ -44,7 +44,7 @@ public function getResponse(string $url, DateTime $modifiedSince = null): Respon * @return ResponseInterface * @throws ClientExceptionInterface */ - protected function request(string $method, string $url, DateTime $modifiedSince = null): ResponseInterface + protected function request(string $method, string $url, ?DateTime $modifiedSince = null): ResponseInterface { $headers = []; diff --git a/src/FeedIo/Adapter/NullClient.php b/src/FeedIo/Adapter/NullClient.php index 96e443b8..3ff0763c 100644 --- a/src/FeedIo/Adapter/NullClient.php +++ b/src/FeedIo/Adapter/NullClient.php @@ -16,7 +16,7 @@ class NullClient implements ClientInterface * @param DateTime|null $modifiedSince * @return \FeedIo\Adapter\ResponseInterface */ - public function getResponse(string $url, DateTime $modifiedSince = null): ResponseInterface + public function getResponse(string $url, ?DateTime $modifiedSince = null): ResponseInterface { return new NullResponse(); } diff --git a/src/FeedIo/Explorer.php b/src/FeedIo/Explorer.php index 9d9846a9..2df63f87 100644 --- a/src/FeedIo/Explorer.php +++ b/src/FeedIo/Explorer.php @@ -36,7 +36,7 @@ public function discover(string $url): array return $feeds; } - protected function extractFeeds(string $html, string $url = null): array + protected function extractFeeds(string $html, ?string $url = null): array { $dom = new DOMDocument(); $dom->loadHTML($html); diff --git a/src/FeedIo/Feed.php b/src/FeedIo/Feed.php index bec8337d..b17bdcdd 100644 --- a/src/FeedIo/Feed.php +++ b/src/FeedIo/Feed.php @@ -49,7 +49,7 @@ public function getUrl(): ?string * @param string|null $url * @return FeedInterface */ - public function setUrl(string $url = null): FeedInterface + public function setUrl(?string $url = null): FeedInterface { $this->url = $url; @@ -64,7 +64,7 @@ public function getDescription(): ?string return $this->description; } - public function setDescription(string $description = null): FeedInterface + public function setDescription(?string $description = null): FeedInterface { $this->description = $description; @@ -76,7 +76,7 @@ public function getLanguage(): ?string return $this->language; } - public function setLanguage(string $language = null): FeedInterface + public function setLanguage(?string $language = null): FeedInterface { $this->language = $language; @@ -88,7 +88,7 @@ public function getLogo(): ?string return $this->logo; } - public function setLogo(string $logo = null): FeedInterface + public function setLogo(?string $logo = null): FeedInterface { $this->logo = $logo; diff --git a/src/FeedIo/Feed/Item.php b/src/FeedIo/Feed/Item.php index b86e9323..ade31781 100644 --- a/src/FeedIo/Feed/Item.php +++ b/src/FeedIo/Feed/Item.php @@ -70,7 +70,7 @@ public function getSummary(): ?string * @param string|null $summary * @return ItemInterface */ - public function setSummary(string $summary = null): ItemInterface + public function setSummary(?string $summary = null): ItemInterface { $this->summary = $summary; @@ -90,7 +90,7 @@ public function getContent(): ?string * @param string|null $content * @return ItemInterface */ - public function setContent(string $content = null): ItemInterface + public function setContent(?string $content = null): ItemInterface { $this->content = $content; diff --git a/src/FeedIo/Feed/Item/Author.php b/src/FeedIo/Feed/Item/Author.php index 6241d0fb..280491fb 100644 --- a/src/FeedIo/Feed/Item/Author.php +++ b/src/FeedIo/Feed/Item/Author.php @@ -26,7 +26,7 @@ public function getName(): ?string * @param string|null $name * @return AuthorInterface */ - public function setName(string $name = null): AuthorInterface + public function setName(?string $name = null): AuthorInterface { $this->name = $name; @@ -45,7 +45,7 @@ public function getUri(): ?string * @param string|null $uri * @return AuthorInterface */ - public function setUri(string $uri = null): AuthorInterface + public function setUri(?string $uri = null): AuthorInterface { $this->uri = $uri; @@ -64,7 +64,7 @@ public function getEmail(): ?string * @param string|null $email * @return AuthorInterface */ - public function setEmail(string $email = null): AuthorInterface + public function setEmail(?string $email = null): AuthorInterface { $this->email = $email; diff --git a/src/FeedIo/Feed/Item/AuthorInterface.php b/src/FeedIo/Feed/Item/AuthorInterface.php index b977f445..d242365f 100644 --- a/src/FeedIo/Feed/Item/AuthorInterface.php +++ b/src/FeedIo/Feed/Item/AuthorInterface.php @@ -19,7 +19,7 @@ public function getName(): ?string; * @param string $name * @return AuthorInterface */ - public function setName(string $name = null): AuthorInterface; + public function setName(?string $name = null): AuthorInterface; /** * @return string @@ -30,7 +30,7 @@ public function getUri(): ?string; * @param string $uri * @return AuthorInterface */ - public function setUri(string $uri = null): AuthorInterface; + public function setUri(?string $uri = null): AuthorInterface; /** * @return string @@ -41,5 +41,5 @@ public function getEmail(): ?string; * @param string $email * @return AuthorInterface */ - public function setEmail(string $email = null): AuthorInterface; + public function setEmail(?string $email = null): AuthorInterface; } diff --git a/src/FeedIo/Feed/ItemInterface.php b/src/FeedIo/Feed/ItemInterface.php index aeecfb6b..18a5751a 100644 --- a/src/FeedIo/Feed/ItemInterface.php +++ b/src/FeedIo/Feed/ItemInterface.php @@ -62,7 +62,7 @@ public function getSummary(): ?string; * @param string|null $summary * @return ItemInterface */ - public function setSummary(string $summary = null): ItemInterface; + public function setSummary(?string $summary = null): ItemInterface; /** * Returns the item's content. Valid for JSONFeed and Atom formats only @@ -75,5 +75,5 @@ public function getContent(): ?string; * @param string|null $content * @return ItemInterface */ - public function setContent(string $content = null): ItemInterface; + public function setContent(?string $content = null): ItemInterface; } diff --git a/src/FeedIo/Feed/Node.php b/src/FeedIo/Feed/Node.php index b5d28fba..87a01d22 100644 --- a/src/FeedIo/Feed/Node.php +++ b/src/FeedIo/Feed/Node.php @@ -38,7 +38,7 @@ public function __construct() $this->categories = new ArrayIterator(); } - public function set(string $name, string $value = null): NodeInterface + public function set(string $name, ?string $value = null): NodeInterface { $element = $this->newElement(); @@ -55,7 +55,7 @@ public function getAuthor(): ?AuthorInterface return $this->author; } - public function setAuthor(AuthorInterface $author = null): NodeInterface + public function setAuthor(?AuthorInterface $author = null): NodeInterface { $this->author = $author; @@ -96,7 +96,7 @@ public function getTitle(): ?string return $this->title; } - public function setTitle(string $title = null): NodeInterface + public function setTitle(?string $title = null): NodeInterface { $this->title = $title; @@ -108,7 +108,7 @@ public function getPublicId(): ?string return $this->publicId; } - public function setPublicId(string $publicId = null): NodeInterface + public function setPublicId(?string $publicId = null): NodeInterface { $this->publicId = $publicId; @@ -120,7 +120,7 @@ public function getLastModified(): ?DateTime return $this->lastModified; } - public function setLastModified(DateTime $lastModified = null): NodeInterface + public function setLastModified(?DateTime $lastModified = null): NodeInterface { $this->lastModified = $lastModified; @@ -142,7 +142,7 @@ public function getLinkForAnalysis(): ?string return $this->linkForAnalysis; } - public function setLink(string $link = null): NodeInterface + public function setLink(?string $link = null): NodeInterface { $this->link = $link; $this->setHost($link); @@ -151,21 +151,21 @@ public function setLink(string $link = null): NodeInterface return $this; } - public function setLinkForAnalysis(string $link = null): NodeInterface + public function setLinkForAnalysis(?string $link = null): NodeInterface { $this->linkForAnalysis = $link; return $this; } - protected function setHost(string $link = null): void + protected function setHost(?string $link = null): void { if (!is_null($link)) { $this->host = '//' . parse_url($link, PHP_URL_HOST); } } - protected function setHostInContent(string $host = null): void + protected function setHostInContent(?string $host = null): void { if (is_null($host)) { return; diff --git a/src/FeedIo/Feed/Node/Category.php b/src/FeedIo/Feed/Node/Category.php index 839d246a..223be8f4 100644 --- a/src/FeedIo/Feed/Node/Category.php +++ b/src/FeedIo/Feed/Node/Category.php @@ -24,7 +24,7 @@ public function getTerm(): ?string * @param string|null $term * @return CategoryInterface */ - public function setTerm(string $term = null): CategoryInterface + public function setTerm(?string $term = null): CategoryInterface { $this->term = $term; @@ -43,7 +43,7 @@ public function getScheme(): ?string * @param string|null $scheme * @return CategoryInterface */ - public function setScheme(string $scheme = null): CategoryInterface + public function setScheme(?string $scheme = null): CategoryInterface { $this->scheme = $scheme; @@ -62,7 +62,7 @@ public function getLabel(): ?string * @param string|null $label * @return CategoryInterface */ - public function setLabel(string $label = null): CategoryInterface + public function setLabel(?string $label = null): CategoryInterface { $this->label = $label; diff --git a/src/FeedIo/Feed/Node/CategoryInterface.php b/src/FeedIo/Feed/Node/CategoryInterface.php index 49a8e83a..de7bd61b 100644 --- a/src/FeedIo/Feed/Node/CategoryInterface.php +++ b/src/FeedIo/Feed/Node/CategoryInterface.php @@ -19,7 +19,7 @@ public function getTerm(): ?string; * @param string|null $term * @return CategoryInterface */ - public function setTerm(string $term = null): CategoryInterface; + public function setTerm(?string $term = null): CategoryInterface; /** * @return null|string @@ -30,7 +30,7 @@ public function getScheme(): ?string; * @param string|null $scheme * @return CategoryInterface */ - public function setScheme(string $scheme = null): CategoryInterface; + public function setScheme(?string $scheme = null): CategoryInterface; /** * @return null|string @@ -41,5 +41,5 @@ public function getLabel(): ?string; * @param string|null $label * @return CategoryInterface */ - public function setLabel(string $label = null): CategoryInterface; + public function setLabel(?string $label = null): CategoryInterface; } diff --git a/src/FeedIo/Feed/Node/Element.php b/src/FeedIo/Feed/Node/Element.php index 23fd875a..af32c34a 100644 --- a/src/FeedIo/Feed/Node/Element.php +++ b/src/FeedIo/Feed/Node/Element.php @@ -53,7 +53,7 @@ public function getValue(): ?string * @param string|null $value * @return ElementInterface */ - public function setValue(string $value = null): ElementInterface + public function setValue(?string $value = null): ElementInterface { $this->value = $value; @@ -86,7 +86,7 @@ public function getAttributes(): iterable * @param string|null $value * @return ElementInterface */ - public function setAttribute(string $name, string $value = null): ElementInterface + public function setAttribute(string $name, ?string $value = null): ElementInterface { $this->attributes[$name] = $value; diff --git a/src/FeedIo/Feed/Node/ElementInterface.php b/src/FeedIo/Feed/Node/ElementInterface.php index 8f01a2bf..7e18c824 100644 --- a/src/FeedIo/Feed/Node/ElementInterface.php +++ b/src/FeedIo/Feed/Node/ElementInterface.php @@ -49,7 +49,7 @@ public function getValue(): ?string; * @param string $value * @return ElementInterface */ - public function setValue(string $value = null): ElementInterface; + public function setValue(?string $value = null): ElementInterface; /** * @param string $name @@ -67,5 +67,5 @@ public function getAttributes(): iterable; * @param string $value * @return ElementInterface */ - public function setAttribute(string $name, string $value = null): ElementInterface; + public function setAttribute(string $name, ?string $value = null): ElementInterface; } diff --git a/src/FeedIo/Feed/NodeInterface.php b/src/FeedIo/Feed/NodeInterface.php index 5a4b501a..d4c6715a 100644 --- a/src/FeedIo/Feed/NodeInterface.php +++ b/src/FeedIo/Feed/NodeInterface.php @@ -27,7 +27,7 @@ public function getAuthor(): ?AuthorInterface; * @param AuthorInterface|null $author * @return NodeInterface */ - public function setAuthor(AuthorInterface $author = null): NodeInterface; + public function setAuthor(?AuthorInterface $author = null): NodeInterface; /** * returns a new AuthorInterface @@ -49,7 +49,7 @@ public function getTitle(): ?string; * @param string $title * @return NodeInterface */ - public function setTitle(string $title = null): NodeInterface; + public function setTitle(?string $title = null): NodeInterface; /** * Returns node's public id @@ -64,7 +64,7 @@ public function getPublicId(): ?string; * @param string $id * @return NodeInterface */ - public function setPublicId(string $id = null): NodeInterface; + public function setPublicId(?string $id = null): NodeInterface; /** * Returns the node's last modified date @@ -79,7 +79,7 @@ public function getLastModified(): ?\DateTime; * @param \DateTime $lastModified * @return NodeInterface */ - public function setLastModified(\DateTime $lastModified = null): NodeInterface; + public function setLastModified(?\DateTime $lastModified = null): NodeInterface; /** * Returns the node's host @@ -101,7 +101,7 @@ public function getLink(): ?string; * @param string $link * @return NodeInterface */ - public function setLink(string $link = null): NodeInterface; + public function setLink(?string $link = null): NodeInterface; /** * returns node's categories @@ -140,5 +140,5 @@ public function getValue(string $name): ?string; * @param string $value element value * @return NodeInterface */ - public function set(string $name, string $value = null): NodeInterface; + public function set(string $name, ?string $value = null): NodeInterface; } diff --git a/src/FeedIo/FeedInterface.php b/src/FeedIo/FeedInterface.php index 7825e45a..f355f0ae 100644 --- a/src/FeedIo/FeedInterface.php +++ b/src/FeedIo/FeedInterface.php @@ -29,7 +29,7 @@ public function getUrl(): ?string; * @param string|null $url * @return FeedInterface */ - public function setUrl(string $url = null): FeedInterface; + public function setUrl(?string $url = null): FeedInterface; /** * Returns feed's description @@ -44,7 +44,7 @@ public function getDescription(): ?string; * @param string|null $description * @return FeedInterface */ - public function setDescription(string $description = null): FeedInterface; + public function setDescription(?string $description = null): FeedInterface; /** * @return string|null @@ -55,7 +55,7 @@ public function getLanguage(): ?string ; * @param string|null $language * @return FeedInterface */ - public function setLanguage(string $language = null): FeedInterface; + public function setLanguage(?string $language = null): FeedInterface; /** * @return string|null @@ -66,7 +66,7 @@ public function getLogo(): ?string ; * @param string|null $logo * @return FeedInterface */ - public function setLogo(string $logo = null): FeedInterface; + public function setLogo(?string $logo = null): FeedInterface; /** * @param ItemInterface $item diff --git a/src/FeedIo/FeedIo.php b/src/FeedIo/FeedIo.php index 19175040..862ac118 100644 --- a/src/FeedIo/FeedIo.php +++ b/src/FeedIo/FeedIo.php @@ -118,7 +118,7 @@ public function discover(string $url): array * @param DateTime|null $modifiedSince * @return Result */ - public function read(string $url, FeedInterface $feed = null, DateTime $modifiedSince = null): Result + public function read(string $url, ?FeedInterface $feed = null, ?DateTime $modifiedSince = null): Result { if (is_null($feed)) { $feed = new Feed(); diff --git a/src/FeedIo/Parser/JsonParser.php b/src/FeedIo/Parser/JsonParser.php index 58dbf8a9..54ddc936 100644 --- a/src/FeedIo/Parser/JsonParser.php +++ b/src/FeedIo/Parser/JsonParser.php @@ -85,7 +85,7 @@ public function parseItems(iterable $items, FeedInterface $feed): JsonParser * @param string|null $default * @return null|string */ - public function readOffset(array $data, string $offsetName, string $default = null): ?string + public function readOffset(array $data, string $offsetName, ?string $default = null): ?string { if (array_key_exists($offsetName, $data)) { return $data[$offsetName]; diff --git a/src/FeedIo/Parser/UrlGenerator.php b/src/FeedIo/Parser/UrlGenerator.php index 9f385b0f..ba0a640e 100644 --- a/src/FeedIo/Parser/UrlGenerator.php +++ b/src/FeedIo/Parser/UrlGenerator.php @@ -11,7 +11,7 @@ class UrlGenerator * @param string $path * @return string */ - public function getAbsolutePath(string $path, string $host = null): string + public function getAbsolutePath(string $path, ?string $host = null): string { if (! parse_url($path, PHP_URL_HOST) && $host) { return $this->generateAbsolutePath($host, $path); diff --git a/src/FeedIo/Reader.php b/src/FeedIo/Reader.php index f7fd058a..174f65cb 100644 --- a/src/FeedIo/Reader.php +++ b/src/FeedIo/Reader.php @@ -63,7 +63,7 @@ public function addParser(ParserAbstract $parser): Reader * @param DateTime|null $modifiedSince * @return Result */ - public function read(string $url, FeedInterface $feed, DateTime $modifiedSince = null): Result + public function read(string $url, FeedInterface $feed, ?DateTime $modifiedSince = null): Result { $this->logger->debug("start reading {$url}"); diff --git a/src/FeedIo/Reader/Result.php b/src/FeedIo/Reader/Result.php index ef7b84c2..c9be2db1 100644 --- a/src/FeedIo/Reader/Result.php +++ b/src/FeedIo/Reader/Result.php @@ -54,7 +54,7 @@ public function getFeed(): FeedInterface return $this->feed; } - public function getItemsSince(DateTime $since = null): iterable + public function getItemsSince(?DateTime $since = null): iterable { $startDate = $since ?? $this->modifiedSince; diff --git a/src/FeedIo/Rule/Atom/LinkNode.php b/src/FeedIo/Rule/Atom/LinkNode.php index 679c0ef9..084b7e78 100644 --- a/src/FeedIo/Rule/Atom/LinkNode.php +++ b/src/FeedIo/Rule/Atom/LinkNode.php @@ -17,7 +17,7 @@ class LinkNode extends RuleAbstract protected RuleSet $ruleSet; - public function __construct(string $nodeName = null) + public function __construct(?string $nodeName = null) { parent::__construct($nodeName); $mediaRule = new Media(); diff --git a/src/FeedIo/Rule/Media.php b/src/FeedIo/Rule/Media.php index 2bc54f58..7d3eb72b 100644 --- a/src/FeedIo/Rule/Media.php +++ b/src/FeedIo/Rule/Media.php @@ -22,7 +22,7 @@ class Media extends RuleAbstract protected UrlGenerator $urlGenerator; - public function __construct(string $nodeName = null) + public function __construct(?string $nodeName = null) { $this->urlGenerator = new UrlGenerator(); parent::__construct($nodeName); @@ -64,7 +64,7 @@ public function setProperty(NodeInterface $node, DOMElement $element): void } } - protected function setUrl(MediaInterface $media, NodeInterface $node, string $url = null): void + protected function setUrl(MediaInterface $media, NodeInterface $node, ?string $url = null): void { if (! is_null($url)) { $media->setUrl( diff --git a/src/FeedIo/Rule/Structure.php b/src/FeedIo/Rule/Structure.php index 29853798..79491347 100644 --- a/src/FeedIo/Rule/Structure.php +++ b/src/FeedIo/Rule/Structure.php @@ -16,7 +16,7 @@ class Structure extends RuleAbstract protected RuleSet $ruleSet; - public function __construct(string $nodeName = null, RuleSet $ruleSet = null) + public function __construct(?string $nodeName = null, ?RuleSet $ruleSet = null) { parent::__construct($nodeName); diff --git a/src/FeedIo/RuleAbstract.php b/src/FeedIo/RuleAbstract.php index 86a52809..6702bd4d 100644 --- a/src/FeedIo/RuleAbstract.php +++ b/src/FeedIo/RuleAbstract.php @@ -14,7 +14,7 @@ abstract class RuleAbstract protected string $nodeName; - public function __construct(string $nodeName = null) + public function __construct(?string $nodeName = null) { $this->nodeName = $nodeName ?? static::NODE_NAME; } @@ -68,14 +68,14 @@ public function apply(DomDocument $document, DOMElement $rootElement, NodeInterf } } - protected function setNonEmptyAttribute(DomElement $element, string $name, string $value = null): void + protected function setNonEmptyAttribute(DomElement $element, string $name, ?string $value = null): void { if (! is_null($value)) { $element->setAttribute($name, $value); } } - protected function appendNonEmptyChild(DomDocument $document, DOMElement $element, string $name, string $value = null): void + protected function appendNonEmptyChild(DomDocument $document, DOMElement $element, string $name, ?string $value = null): void { if (! is_null($value)) { $element->appendChild($document->createElement($name, $value)); diff --git a/src/FeedIo/RuleSet.php b/src/FeedIo/RuleSet.php index 3116b5dd..1dc39fdd 100644 --- a/src/FeedIo/RuleSet.php +++ b/src/FeedIo/RuleSet.php @@ -15,7 +15,7 @@ class RuleSet protected RuleAbstract $default; - public function __construct(RuleAbstract $default = null) + public function __construct(?RuleAbstract $default = null) { $this->rules = new \ArrayIterator(array()); $this->default = is_null($default) ? new OptionalField() : $default;