Skip to content

Commit

Permalink
Merge pull request #854 from jtojnar/one-eight-ci
Browse files Browse the repository at this point in the history
[1.8] ci: Fix coding style
  • Loading branch information
mblaney committed Dec 19, 2023
2 parents 419f1ec + 8a98747 commit 5f584cd
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 56 deletions.
10 changes: 5 additions & 5 deletions build/compile.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
define('SP_PATH', dirname(__FILE__, 2));
define('COMPILED', SP_PATH . DIRECTORY_SEPARATOR . 'SimplePie.compiled.php');

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

if (! function_exists('str_ends_with')) {
if (!function_exists('str_ends_with')) {
function str_ends_with(string $haystack, string $needle): bool
{
return $needle === '' || $needle === substr($haystack, - strlen($needle));
return $needle === '' || $needle === substr($haystack, -strlen($needle));
}
}

Expand Down Expand Up @@ -57,7 +57,7 @@ function remove_header($contents)
}
break;
case T_DECLARE:
if (! $stripped_declare && ! $in_declare_strip) {
if (!$stripped_declare && !$in_declare_strip) {
$in_declare_strip = true;
continue 2;
}
Expand Down Expand Up @@ -115,7 +115,7 @@ function remove_header($contents)
$pos = strpos($contents, ';');
$namespace_name = substr($contents, 0, $pos);

$contents = $namespace_name . " {\n\n" . substr($contents, $pos+1) . "\n\n}";
$contents = $namespace_name . " {\n\n" . substr($contents, $pos + 1) . "\n\n}";
} else {
// use bracketed syntax for global namespace
$contents = "namespace {\n\n" . $contents . "\n\n}";
Expand Down
4 changes: 2 additions & 2 deletions src/Cache/BaseDataCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ public function get_data(string $key, $default = null)
{
$data = $this->cache->load();

if (! is_array($data)) {
if (!is_array($data)) {
return $default;
}

// ignore data if internal cache expiration time is not set
if (! array_key_exists('__cache_expiration_time', $data)) {
if (!array_key_exists('__cache_expiration_time', $data)) {
return $default;
}

Expand Down
8 changes: 4 additions & 4 deletions src/Cache/DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ protected static function prepare_simplepie_object_for_cache($data)
}

if (isset($data->data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['feed'][0])) {
$channel =& $data->data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['feed'][0];
$channel = &$data->data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['feed'][0];
} elseif (isset($data->data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['feed'][0])) {
$channel =& $data->data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['feed'][0];
$channel = &$data->data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['feed'][0];
} elseif (isset($data->data['child'][\SimplePie\SimplePie::NAMESPACE_RDF]['RDF'][0])) {
$channel =& $data->data['child'][\SimplePie\SimplePie::NAMESPACE_RDF]['RDF'][0];
$channel = &$data->data['child'][\SimplePie\SimplePie::NAMESPACE_RDF]['RDF'][0];
} elseif (isset($data->data['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['rss'][0]['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['channel'][0])) {
$channel =& $data->data['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['rss'][0]['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['channel'][0];
$channel = &$data->data['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['rss'][0]['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['channel'][0];
} else {
$channel = null;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Cache/MySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,13 @@ public function load()

if ($items !== 0) {
if (isset($data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['feed'][0])) {
$feed =& $data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['feed'][0];
$feed = &$data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['feed'][0];
} elseif (isset($data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['feed'][0])) {
$feed =& $data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['feed'][0];
$feed = &$data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['feed'][0];
} elseif (isset($data['child'][\SimplePie\SimplePie::NAMESPACE_RDF]['RDF'][0])) {
$feed =& $data['child'][\SimplePie\SimplePie::NAMESPACE_RDF]['RDF'][0];
$feed = &$data['child'][\SimplePie\SimplePie::NAMESPACE_RDF]['RDF'][0];
} elseif (isset($data['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['rss'][0])) {
$feed =& $data['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['rss'][0];
$feed = &$data['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['rss'][0];
} else {
$feed = null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/Psr16.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function get_data(string $key, $default = null)
{
$data = $this->cache->get($key, $default);

if (! is_array($data) || $data === $default) {
if (!is_array($data) || $data === $default) {
return $default;
}

Expand Down
16 changes: 8 additions & 8 deletions src/Enclosure.php
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ public function get_size()
{
$length = $this->get_length();
if ($length !== null) {
return round($length/1048576, 2);
return round($length / 1048576, 2);
}

return null;
Expand Down Expand Up @@ -811,7 +811,7 @@ public function get_width()
* @param array|string $options See first parameter to {@see embed}
* @return string HTML string to output
*/
public function native_embed($options='')
public function native_embed($options = '')
{
return $this->embed($options, true);
}
Expand Down Expand Up @@ -942,9 +942,9 @@ public function embed($options = '', $native = false)
if ($height === 'auto') {
$width = 480;
} elseif ($widescreen) {
$width = round((intval($height)/9)*16);
$width = round((intval($height) / 9) * 16);
} else {
$width = round((intval($height)/3)*4);
$width = round((intval($height) / 3) * 4);
}
} else {
$width = '100%';
Expand All @@ -962,9 +962,9 @@ public function embed($options = '', $native = false)
$height = 360;
}
} elseif ($widescreen) {
$height = round((intval($width)/16)*9);
$height = round((intval($width) / 16) * 9);
} else {
$height = round((intval($width)/4)*3);
$height = round((intval($width) / 4) * 3);
}
} else {
$height = 376;
Expand Down Expand Up @@ -1114,7 +1114,7 @@ public function get_real_type($find_handler = false)
$type = 'audio/x-ms-wma';
break;

// Video mime-types
// Video mime-types
case '3gp':
case '3gpp':
$type = 'video/3gpp';
Expand Down Expand Up @@ -1177,7 +1177,7 @@ public function get_real_type($find_handler = false)
$type = 'video/x-ms-wvx';
break;

// Flash mime-types
// Flash mime-types
case 'spl':
$type = 'application/futuresplash';
break;
Expand Down
6 changes: 3 additions & 3 deletions src/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -877,12 +877,12 @@ public function get_links($rel = 'alternate')
if ($this->registry->call(Misc::class, 'is_isegment_nz_nc', [$key])) {
if (isset($this->data['links'][\SimplePie\SimplePie::IANA_LINK_RELATIONS_REGISTRY . $key])) {
$this->data['links'][\SimplePie\SimplePie::IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][\SimplePie\SimplePie::IANA_LINK_RELATIONS_REGISTRY . $key]);
$this->data['links'][$key] =& $this->data['links'][\SimplePie\SimplePie::IANA_LINK_RELATIONS_REGISTRY . $key];
$this->data['links'][$key] = &$this->data['links'][\SimplePie\SimplePie::IANA_LINK_RELATIONS_REGISTRY . $key];
} else {
$this->data['links'][\SimplePie\SimplePie::IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
$this->data['links'][\SimplePie\SimplePie::IANA_LINK_RELATIONS_REGISTRY . $key] = &$this->data['links'][$key];
}
} elseif (substr($key, 0, 41) === \SimplePie\SimplePie::IANA_LINK_RELATIONS_REGISTRY) {
$this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
$this->data['links'][substr($key, 41)] = &$this->data['links'][$key];
}
$this->data['links'][$key] = array_unique($this->data['links'][$key]);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ public function tag_open($parser, $tag, $attributes)
$this->data['data'] .= '>';
}
} else {
$this->datas[] =& $this->data;
$this->data =& $this->data['child'][end($this->namespace)][end($this->element)][];
$this->datas[] = &$this->data;
$this->data = &$this->data['child'][end($this->namespace)][end($this->element)][];
$this->data = ['data' => '', 'attribs' => $attribs, 'xml_base' => end($this->xml_base), 'xml_base_explicit' => end($this->xml_base_explicit), 'xml_lang' => end($this->xml_lang)];
if ((end($this->namespace) === \SimplePie\SimplePie::NAMESPACE_ATOM_03 && in_array(end($this->element), ['title', 'tagline', 'copyright', 'info', 'summary', 'content']) && isset($attribs['']['mode']) && $attribs['']['mode'] === 'xml')
|| (end($this->namespace) === \SimplePie\SimplePie::NAMESPACE_ATOM_10 && in_array(end($this->element), ['rights', 'subtitle', 'summary', 'info', 'title', 'content']) && isset($attribs['']['type']) && $attribs['']['type'] === 'xhtml')
Expand Down Expand Up @@ -333,7 +333,7 @@ public function tag_close($parser, $tag)
}
}
if ($this->current_xhtml_construct === -1) {
$this->data =& $this->datas[count($this->datas) - 1];
$this->data = &$this->datas[count($this->datas) - 1];
array_pop($this->datas);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function register($type, $class, $legacy = false)
$type = $this->legacyTypes[$type];
}

if (! array_key_exists($type, $this->default)) {
if (!array_key_exists($type, $this->default)) {
return false;
}

Expand Down Expand Up @@ -196,7 +196,7 @@ public function get_class($type)
$type = $this->legacyTypes[$type];
}

if (! array_key_exists($type, $this->default)) {
if (!array_key_exists($type, $this->default)) {
return null;
}

Expand Down
10 changes: 5 additions & 5 deletions src/Sanitize.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function pass_cache_data($enable_cache = true, $cache_location = './cache
$this->cache_location = (string) $cache_location;
}

if (! is_string($cache_name_function) && ! is_object($cache_name_function) && ! $cache_name_function instanceof NameFilter) {
if (!is_string($cache_name_function) && !is_object($cache_name_function) && !$cache_name_function instanceof NameFilter) {
throw new InvalidArgumentException(sprintf(
'%s(): Argument #3 ($cache_name_function) must be of type %s',
__METHOD__,
Expand Down Expand Up @@ -296,15 +296,15 @@ public function set_https_domains($domains)
foreach ($domains as $domain) {
$domain = trim($domain, ". \t\n\r\0\x0B");
$segments = array_reverse(explode('.', $domain));
$node =& $this->https_domains;
$node = &$this->https_domains;
foreach ($segments as $segment) {//Build a tree
if ($node === true) {
break;
}
if (!isset($node[$segment])) {
$node[$segment] = [];
}
$node =& $node[$segment];
$node = &$node[$segment];
}
$node = true;
}
Expand All @@ -317,10 +317,10 @@ protected function is_https_domain($domain)
{
$domain = trim($domain, '. ');
$segments = array_reverse(explode('.', $domain));
$node =& $this->https_domains;
$node = &$this->https_domains;
foreach ($segments as $segment) {//Explore the tree
if (isset($node[$segment])) {
$node =& $node[$segment];
$node = &$node[$segment];
} else {
break;
}
Expand Down
16 changes: 8 additions & 8 deletions src/SimplePie.php
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ public function set_file(&$file)
if ($file instanceof \SimplePie\File) {
$this->feed_url = $file->url;
$this->permanent_url = $this->feed_url;
$this->file =& $file;
$this->file = &$file;
return true;
}
return false;
Expand Down Expand Up @@ -1665,7 +1665,7 @@ public function init()

// Cache the file if caching is enabled
$this->data['cache_expiration_time'] = $this->cache_duration + time();
if ($cache && ! $cache->set_data($this->get_cache_filename($this->feed_url), $this->data, $this->cache_duration)) {
if ($cache && !$cache->set_data($this->get_cache_filename($this->feed_url), $this->data, $this->cache_duration)) {
trigger_error("$this->cache_location is not writable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING);
}
return true;
Expand Down Expand Up @@ -1715,7 +1715,7 @@ protected function fetch_data(&$cache)
$cache = new BaseDataCache($cache);
}

if ($cache !== false && ! $cache instanceof DataCache) {
if ($cache !== false && !$cache instanceof DataCache) {
throw new InvalidArgumentException(sprintf(
'%s(): Argument #1 ($cache) must be of type %s|false',
__METHOD__,
Expand Down Expand Up @@ -1773,7 +1773,7 @@ protected function fetch_data(&$cache)
$headers['if-none-match'] = $this->data['headers']['etag'];
}

$file = $this->registry->create(File::class, [$this->feed_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen, $this->curl_options]);
$file = $this->registry->create(File::class, [$this->feed_url, $this->timeout / 10, 5, $headers, $this->useragent, $this->force_fsockopen, $this->curl_options]);
$this->status_code = $file->status_code;

if ($file->success) {
Expand Down Expand Up @@ -1810,7 +1810,7 @@ protected function fetch_data(&$cache)
// If we don't already have the file (it'll only exist if we've opened it to check if the cache has been modified), open it.
if (!isset($file)) {
if ($this->file instanceof \SimplePie\File && $this->file->url === $this->feed_url) {
$file =& $this->file;
$file = &$this->file;
} else {
$headers = [
'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1',
Expand Down Expand Up @@ -2640,12 +2640,12 @@ public function get_links($rel = 'alternate')
if ($this->registry->call(Misc::class, 'is_isegment_nz_nc', [$key])) {
if (isset($this->data['links'][self::IANA_LINK_RELATIONS_REGISTRY . $key])) {
$this->data['links'][self::IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][self::IANA_LINK_RELATIONS_REGISTRY . $key]);
$this->data['links'][$key] =& $this->data['links'][self::IANA_LINK_RELATIONS_REGISTRY . $key];
$this->data['links'][$key] = &$this->data['links'][self::IANA_LINK_RELATIONS_REGISTRY . $key];
} else {
$this->data['links'][self::IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
$this->data['links'][self::IANA_LINK_RELATIONS_REGISTRY . $key] = &$this->data['links'][$key];
}
} elseif (substr($key, 0, 41) === self::IANA_LINK_RELATIONS_REGISTRY) {
$this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
$this->data['links'][substr($key, 41)] = &$this->data['links'][$key];
}
$this->data['links'][$key] = array_unique($this->data['links'][$key]);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,12 @@ public function get_links($rel = 'alternate')
if ($this->registry->call(Misc::class, 'is_isegment_nz_nc', [$key])) {
if (isset($this->data['links'][\SimplePie\SimplePie::IANA_LINK_RELATIONS_REGISTRY . $key])) {
$this->data['links'][\SimplePie\SimplePie::IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][\SimplePie\SimplePie::IANA_LINK_RELATIONS_REGISTRY . $key]);
$this->data['links'][$key] =& $this->data['links'][\SimplePie\SimplePie::IANA_LINK_RELATIONS_REGISTRY . $key];
$this->data['links'][$key] = &$this->data['links'][\SimplePie\SimplePie::IANA_LINK_RELATIONS_REGISTRY . $key];
} else {
$this->data['links'][\SimplePie\SimplePie::IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
$this->data['links'][\SimplePie\SimplePie::IANA_LINK_RELATIONS_REGISTRY . $key] = &$this->data['links'][$key];
}
} elseif (substr($key, 0, 41) === \SimplePie\SimplePie::IANA_LINK_RELATIONS_REGISTRY) {
$this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
$this->data['links'][substr($key, 41)] = &$this->data['links'][$key];
}
$this->data['links'][$key] = array_unique($this->data['links'][$key]);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/CachingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function testInitWithDifferentCacheStateCallsCacheCorrectly(
// Set current cached data and mtime
$psr16->method('get')->willReturnCallback(function ($key, $default) use ($currentDataCached, $currentMtime) {
// Set current mtime
if (substr($key, - strlen('_mtime')) === '_mtime') {
if (substr($key, -strlen('_mtime')) === '_mtime') {
return $currentMtime;
}

Expand All @@ -92,7 +92,7 @@ public function testInitWithDifferentCacheStateCallsCacheCorrectly(
// Test data written
$psr16->method('set')->willReturnCallback(function ($key, $value, $ttl) use (&$writtenData) {
// Ignore setting of the _mtime value
if (substr($key, - strlen('_mtime')) !== '_mtime') {
if (substr($key, -strlen('_mtime')) !== '_mtime') {
$writtenData = $value;
}

Expand Down

0 comments on commit 5f584cd

Please sign in to comment.