Skip to content

Commit

Permalink
Declare strict_types=1 in every file (#763)
Browse files Browse the repository at this point in the history
* declare strict_types=1 in every file

* declare strict_types=1 in IRI and Parse Date class

* declare strict_types=1 in Misc class, fix bug

* declare strict_types=1 in SimplePie class

* BC for PHP < 8.0

* Strip declare statement in compiled file

* Fix many errors for PHPStan Level 1

* do not round() int

* Fix get_image_height() and get_image_width() returning int|null

Returning float instead of int was wrongly introduced in commt 33a8f76

According to the RSS 2.0 spec height and width must be the number of pixels.

see https://www.rssboard.org/rss-specification#ltimagegtSubelementOfLtchannelgt

* Update CHANGELOG.md

* clarify some statements

* Fix $encoded declatation

* Fix $valid declaration

* fix CS by running php-cs-fixer
  • Loading branch information
Art4 committed Dec 13, 2022
1 parent 93fe459 commit efe70f4
Show file tree
Hide file tree
Showing 131 changed files with 336 additions and 35 deletions.
1 change: 0 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
'@PSR12' => true,
'@PHP71Migration' => true,
'@PHP71Migration:risky' => true,
'declare_strict_types' => false,
'void_return' => false,
'@PHPUnit84Migration:risky' => true,
])
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- The class `SimplePie\Cache\Redis` is deprecated, use implementation of `Psr\SimpleCache\CacheInterface` instead
- The interface `SimplePie\Cache\Base` is deprecated, use interface `Psr\SimpleCache\CacheInterface` instead

### Fixed

- The method `SimplePie\SimplePie::get_image_height()` returns the pixel number as `int` instead of `float`
- The method `SimplePie\SimplePie::get_image_width()` returns the pixel number as `int` instead of `float`

## [1.7.0](https://github.com/simplepie/simplepie/compare/1.6.0...1.7.0) - 2022-09-30

### Added
Expand Down
2 changes: 2 additions & 0 deletions build/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);

require_once dirname(__DIR__) . '/SimplePie.compiled.php';
require_once dirname(__DIR__) . '/vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php';
2 changes: 2 additions & 0 deletions build/charset.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

require_once '../autoloader.php';

function normalize_character_set($charset)
Expand Down
32 changes: 30 additions & 2 deletions build/compile.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<?php

declare(strict_types=1);

// Set up our constants
define('SP_PATH', dirname(__FILE__, 2));
define('COMPILED', SP_PATH . DIRECTORY_SEPARATOR . 'SimplePie.compiled.php');

if (! function_exists('str_starts_with')) {
function str_starts_with(string $haystack, string $needle)
function str_starts_with(string $haystack, string $needle): bool
{
return strncmp($haystack, $needle, strlen($needle)) === 0;
}
}

if (! function_exists('str_ends_with')) {
function str_ends_with(string $haystack, string $needle)
function str_ends_with(string $haystack, string $needle): bool
{
return $needle === '' || $needle === substr($haystack, - strlen($needle));
}
Expand All @@ -24,8 +26,18 @@ function remove_header($contents)
$stripped_source = '';
$stripped_doc = false;
$stripped_open = false;
$stripped_declare = false;
$in_declare_strip = false;

foreach ($tokens as $value) {
if (is_string($value)) {
if ($in_declare_strip) {
if ($value === ';') {
$in_declare_strip = false;
$stripped_declare = true;
}
continue;
}
$stripped_source .= "{$value}";
continue;
}
Expand All @@ -36,6 +48,22 @@ function remove_header($contents)
continue 2;
}
break;
case T_STRING:
if ($in_declare_strip) {
continue 2;
}
break;
case T_LNUMBER:
if ($in_declare_strip) {
continue 2;
}
break;
case T_DECLARE:
if (! $stripped_declare && ! $in_declare_strip) {
$in_declare_strip = true;
continue 2;
}
break;
case T_OPEN_TAG:
if (!$stripped_open) {
$stripped_open = true;
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/Author.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/Cache.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/Cache/Base.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/Cache/DB.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/Cache/File.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/Cache/Memcache.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/Cache/Memcached.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/Cache/MySQL.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/Cache/Redis.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* SimplePie Redis Cache Extension
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/Caption.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/Category.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/Content/Type/Sniffer.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/Copyright.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/Core.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/Credit.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/Decode/HTML/Entities.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/Enclosure.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/Exception.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/File.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/HTTP/Parser.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/IRI.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/Item.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/Locator.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/Misc.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/Net/IPv6.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/Parse/Date.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/Parser.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/Rating.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/Registry.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/Restriction.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/Sanitize.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/Source.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/XML/Declaration/Parser.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions library/SimplePie/gzdecode.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions src/Author.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions src/Cache.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions src/Cache/Base.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions src/Cache/BaseDataCache.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions src/Cache/DB.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions src/Cache/DataCache.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
2 changes: 2 additions & 0 deletions src/Cache/File.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* SimplePie
*
Expand Down
Loading

0 comments on commit efe70f4

Please sign in to comment.