Replaced uses of floatval and intval with casts.

This commit is contained in:
flash 2023-01-01 19:00:00 +00:00
parent 9bb07806a0
commit d166428729
20 changed files with 52 additions and 52 deletions

View file

@ -1 +1 @@
0.2301.11846 0.2301.11859

View file

@ -1,7 +1,7 @@
<?php <?php
// MariaDBResult.php // MariaDBResult.php
// Created: 2021-05-02 // Created: 2021-05-02
// Updated: 2022-02-16 // Updated: 2023-01-01
namespace Index\Data\MariaDB; namespace Index\Data\MariaDB;
@ -82,11 +82,11 @@ abstract class MariaDBResult implements IDbResult {
} }
public function getInteger(int|string $index): int { public function getInteger(int|string $index): int {
return intval($this->getValue($index)); return (int)$this->getValue($index);
} }
public function getFloat(int|string $index): float { public function getFloat(int|string $index): float {
return floatval($this->getValue($index)); return (float)$this->getValue($index);
} }
public function getStream(int|string $index): ?Stream { public function getStream(int|string $index): ?Stream {

View file

@ -1,7 +1,7 @@
<?php <?php
// SQLiteResult.php // SQLiteResult.php
// Created: 2021-05-02 // Created: 2021-05-02
// Updated: 2022-02-16 // Updated: 2023-01-01
namespace Index\Data\SQLite; namespace Index\Data\SQLite;
@ -68,11 +68,11 @@ class SQLiteResult implements IDbResult {
} }
public function getInteger(int|string $index): int { public function getInteger(int|string $index): int {
return intval($this->getValue($index)); return (int)$this->getValue($index);
} }
public function getFloat(int|string $index): float { public function getFloat(int|string $index): float {
return floatval($this->getValue($index)); return (float)$this->getValue($index);
} }
/** /**

View file

@ -1,7 +1,7 @@
<?php <?php
// AcceptEncodingHeader.php // AcceptEncodingHeader.php
// Created: 2022-02-14 // Created: 2022-02-14
// Updated: 2022-02-27 // Updated: 2023-01-01
namespace Index\Http\Headers; namespace Index\Http\Headers;
@ -53,7 +53,7 @@ class AcceptEncodingHeader {
foreach($part as $param) { foreach($part as $param) {
if(substr($param, 0, 2) === 'q=') { if(substr($param, 0, 2) === 'q=') {
$algo->quality = min(0, max(1, floatval(substr($param, 2)))); $algo->quality = min(0, max(1, (float)substr($param, 2)));
break; break;
} }
} }

View file

@ -1,7 +1,7 @@
<?php <?php
// AcceptLanguageHeader.php // AcceptLanguageHeader.php
// Created: 2022-02-14 // Created: 2022-02-14
// Updated: 2022-02-27 // Updated: 2023-01-01
namespace Index\Http\Headers; namespace Index\Http\Headers;
@ -54,7 +54,7 @@ class AcceptLanguageHeader {
foreach($part as $param) { foreach($part as $param) {
if(substr($param, 0, 2) === 'q=') { if(substr($param, 0, 2) === 'q=') {
$lang->quality = min(0, max(1, floatval(substr($param, 2)))); $lang->quality = min(0, max(1, (float)substr($param, 2)));
break; break;
} }
} }

View file

@ -1,7 +1,7 @@
<?php <?php
// AcceptTransferEncodingHeader.php // AcceptTransferEncodingHeader.php
// Created: 2022-02-14 // Created: 2022-02-14
// Updated: 2022-02-27 // Updated: 2023-01-01
namespace Index\Http\Headers; namespace Index\Http\Headers;
@ -53,7 +53,7 @@ class AcceptTransferEncodingHeader {
foreach($part as $param) { foreach($part as $param) {
if(substr($param, 0, 2) === 'q=') { if(substr($param, 0, 2) === 'q=') {
$algo->quality = min(0, max(1, floatval(substr($param, 2)))); $algo->quality = min(0, max(1, (float)substr($param, 2)));
break; break;
} }
} }

View file

@ -1,7 +1,7 @@
<?php <?php
// ContentLengthHeader.php // ContentLengthHeader.php
// Created: 2022-02-14 // Created: 2022-02-14
// Updated: 2022-02-27 // Updated: 2023-01-01
namespace Index\Http\Headers; namespace Index\Http\Headers;
@ -19,6 +19,6 @@ class ContentLengthHeader {
} }
public static function parse(HttpHeader $header): ContentLengthHeader { public static function parse(HttpHeader $header): ContentLengthHeader {
return new ContentLengthHeader(intval($header->getFirstLine())); return new ContentLengthHeader((int)$header->getFirstLine());
} }
} }

View file

@ -1,7 +1,7 @@
<?php <?php
// ContentRangeHeader.php // ContentRangeHeader.php
// Created: 2022-02-14 // Created: 2022-02-14
// Updated: 2022-02-27 // Updated: 2023-01-01
namespace Index\Http\Headers; namespace Index\Http\Headers;
@ -56,7 +56,7 @@ class ContentRangeHeader {
$size = trim($parts[1] ?? '*'); $size = trim($parts[1] ?? '*');
if($size !== '*') if($size !== '*')
$size = max(0, intval($size)); $size = max(0, (int)$size);
else else
$size = -1; $size = -1;
@ -64,8 +64,8 @@ class ContentRangeHeader {
if($range !== '*') { if($range !== '*') {
$parts = explode('-', $range, 2); $parts = explode('-', $range, 2);
$rangeStart = intval(trim($parts[0])); $rangeStart = (int)trim($parts[0]);
$rangeEnd = intval(trim($parts[1] ?? '0')); $rangeEnd = (int)trim($parts[1] ?? '0');
} else } else
$rangeStart = $rangeEnd = -1; $rangeStart = $rangeEnd = -1;

View file

@ -1,7 +1,7 @@
<?php <?php
// ExpectHeader.php // ExpectHeader.php
// Created: 2022-02-14 // Created: 2022-02-14
// Updated: 2022-02-14 // Updated: 2023-01-01
namespace Index\Http\Headers; namespace Index\Http\Headers;
@ -26,6 +26,6 @@ class ExpectHeader {
public static function parse(HttpHeader $header): ExpectHeader { public static function parse(HttpHeader $header): ExpectHeader {
$value = explode('-', $header->getFirstLine(), 2); $value = explode('-', $header->getFirstLine(), 2);
return new ExpectHeader(intval($value[0]), $value[1] ?? ''); return new ExpectHeader((int)$value[0], $value[1] ?? '');
} }
} }

View file

@ -1,7 +1,7 @@
<?php <?php
// HostHeader.php // HostHeader.php
// Created: 2022-02-14 // Created: 2022-02-14
// Updated: 2022-02-14 // Updated: 2023-01-01
namespace Index\Http\Headers; namespace Index\Http\Headers;
@ -30,6 +30,6 @@ class HostHeader {
public static function parse(HttpHeader $header): HostHeader { public static function parse(HttpHeader $header): HostHeader {
$parts = explode(':', $header->getFirstLine(), 2); $parts = explode(':', $header->getFirstLine(), 2);
return new HostHeader($parts[0], intval($parts[1] ?? '-1')); return new HostHeader($parts[0], (int)($parts[1] ?? '-1'));
} }
} }

View file

@ -1,7 +1,7 @@
<?php <?php
// KeepAliveHeader.php // KeepAliveHeader.php
// Created: 2022-02-14 // Created: 2022-02-14
// Updated: 2022-02-15 // Updated: 2023-01-01
namespace Index\Http\Headers; namespace Index\Http\Headers;
@ -31,9 +31,9 @@ class KeepAliveHeader {
foreach($params as $param) { foreach($params as $param) {
if(str_starts_with($param, 'timeout=')) if(str_starts_with($param, 'timeout='))
$timeOut = intval(substr($param, 8)); $timeOut = (int)substr($param, 8);
elseif(str_starts_with($param, 'max=')) elseif(str_starts_with($param, 'max='))
$max = intval(substr($param, 4)); $max = (int)substr($param, 4);
if($timeOut >= 0 && $max >= 0) if($timeOut >= 0 && $max >= 0)
break; break;
} }

View file

@ -1,7 +1,7 @@
<?php <?php
// RangeHeader.php // RangeHeader.php
// Created: 2022-02-14 // Created: 2022-02-14
// Updated: 2022-02-27 // Updated: 2023-01-01
namespace Index\Http\Headers; namespace Index\Http\Headers;
@ -45,14 +45,14 @@ class RangeHeader {
if($start === '' && is_numeric($end)) { if($start === '' && is_numeric($end)) {
$range->type = 'suffix-length'; $range->type = 'suffix-length';
$range->length = intval($end); $range->length = (int)$end;
} elseif(is_numeric($start) && $end === '') { } elseif(is_numeric($start) && $end === '') {
$range->type = 'start'; $range->type = 'start';
$range->start = intval($start); $range->start = (int)$start;
} else { } else {
$range->type = 'range'; $range->type = 'range';
$range->start = intval($start); $range->start = (int)$start;
$range->end = intval($end); $range->end = (int)$end;
} }
} }

View file

@ -1,7 +1,7 @@
<?php <?php
// HttpRequest.php // HttpRequest.php
// Created: 2022-02-08 // Created: 2022-02-08
// Updated: 2022-02-27 // Updated: 2023-01-01
namespace Index\Http; namespace Index\Http;
@ -93,7 +93,7 @@ class HttpRequest extends HttpMessage {
$contentType = null; $contentType = null;
} }
elseif($nameLower === 'content-length') elseif($nameLower === 'content-length')
$contentLength = intval($value); $contentLength = (int)$value;
$build->setHeader($name, $value); $build->setHeader($name, $value);
} }

View file

@ -1,7 +1,7 @@
<?php <?php
// DnsEndPoint.php // DnsEndPoint.php
// Created: 2021-05-02 // Created: 2021-05-02
// Updated: 2022-02-28 // Updated: 2023-01-01
namespace Index\Net; namespace Index\Net;
@ -49,7 +49,7 @@ class DnsEndPoint extends EndPoint implements Stringable {
$parts = explode(':', $string); $parts = explode(':', $string);
if(count($parts) < 2) if(count($parts) < 2)
throw new InvalidArgumentException('$string is not a valid host and port combo.'); throw new InvalidArgumentException('$string is not a valid host and port combo.');
return new DnsEndPoint($parts[0], intval($parts[1])); return new DnsEndPoint($parts[0], (int)$parts[1]);
} }
public function __toString(): string { public function __toString(): string {

View file

@ -1,7 +1,7 @@
<?php <?php
// IPAddressRange.php // IPAddressRange.php
// Created: 2021-04-26 // Created: 2021-04-26
// Updated: 2022-02-27 // Updated: 2023-01-01
namespace Index\Net; namespace Index\Net;
@ -92,6 +92,6 @@ final class IPAddressRange implements JsonSerializable, Stringable, IEquatable {
$parts = explode('/', $cidr, 2); $parts = explode('/', $cidr, 2);
if(empty($parts[0]) || empty($parts[1])) if(empty($parts[0]) || empty($parts[1]))
throw new InvalidArgumentException('$cidr is not a valid CIDR range.'); throw new InvalidArgumentException('$cidr is not a valid CIDR range.');
return new static(IPAddress::parse($parts[0]), intval($parts[1])); return new static(IPAddress::parse($parts[0]), (int)$parts[1]);
} }
} }

View file

@ -1,7 +1,7 @@
<?php <?php
// IPEndPoint.php // IPEndPoint.php
// Created: 2021-04-30 // Created: 2021-04-30
// Updated: 2022-02-28 // Updated: 2023-01-01
namespace Index\Net; namespace Index\Net;
@ -51,13 +51,13 @@ class IPEndPoint extends EndPoint {
if($closing === false) if($closing === false)
throw new InvalidArgumentException('$string is not a valid IP end point.'); throw new InvalidArgumentException('$string is not a valid IP end point.');
$ip = substr($string, 1, $closing - 1); $ip = substr($string, 1, $closing - 1);
$port = intval(substr($string, $closing + 2)); $port = (int)substr($string, $closing + 2);
} else { // IPv4 } else { // IPv4
$parts = explode(':', $string, 2); $parts = explode(':', $string, 2);
if(count($parts) < 2) if(count($parts) < 2)
throw new InvalidArgumentException('$string is not a valid IP end point.'); throw new InvalidArgumentException('$string is not a valid IP end point.');
$ip = $parts[0]; $ip = $parts[0];
$port = intval($parts[1]); $port = (int)$parts[1];
} }
return new IPEndPoint(IPAddress::parse($ip), $port); return new IPEndPoint(IPAddress::parse($ip), $port);

View file

@ -1,7 +1,7 @@
<?php <?php
// Base62Serialiser.php // Base62Serialiser.php
// Created: 2022-01-28 // Created: 2022-01-28
// Updated: 2022-02-27 // Updated: 2023-01-01
namespace Index\Serialisation; namespace Index\Serialisation;
@ -20,7 +20,7 @@ class Base62Serialiser extends Serialiser {
* @return string Base64 string representing the integer. * @return string Base64 string representing the integer.
*/ */
public function serialise(mixed $input): string { public function serialise(mixed $input): string {
$input = intval($input); $input = (int)$input;
$output = ''; $output = '';
for($i = floor(log10($input) / log10(62)); $i >= 0; --$i) { for($i = floor(log10($input) / log10(62)); $i >= 0; --$i) {

View file

@ -1,7 +1,7 @@
<?php <?php
// BencodeSerialiser.php // BencodeSerialiser.php
// Created: 2022-01-13 // Created: 2022-01-13
// Updated: 2022-02-27 // Updated: 2023-01-01
namespace Index\Serialisation; namespace Index\Serialisation;
@ -108,7 +108,7 @@ class BencodeSerialiser extends Serialiser {
$number .= $char; $number .= $char;
} }
return intval($number); return (int)$number;
case 'l': case 'l':
$list = []; $list = [];
@ -165,7 +165,7 @@ class BencodeSerialiser extends Serialiser {
$length .= $char; $length .= $char;
} }
return $input->read(intval($length)); return $input->read((int)$length);
} }
} }
} }

View file

@ -1,7 +1,7 @@
<?php <?php
// XString.php // XString.php
// Created: 2022-02-03 // Created: 2022-02-03
// Updated: 2022-02-27 // Updated: 2023-01-01
namespace Index; namespace Index;
@ -14,11 +14,11 @@ final class XString {
} }
public static function toInt(string $value, int $base = 10): int { public static function toInt(string $value, int $base = 10): int {
return intval($value, $base); return $base === 10 ? (int)$value : intval($value, $base);
} }
public static function toFloat(string $value): float { public static function toFloat(string $value): float {
return floatval($value); return (float)$value;
} }
public static function escape( public static function escape(

View file

@ -1,7 +1,7 @@
<?php <?php
// EnvironmentTest.php // EnvironmentTest.php
// Created: 2021-05-02 // Created: 2021-05-02
// Updated: 2022-02-27 // Updated: 2023-01-01
declare(strict_types=1); declare(strict_types=1);
@ -32,9 +32,9 @@ final class EnvironmentTest extends TestCase {
$rawVersion = explode('.', $strVersion); $rawVersion = explode('.', $strVersion);
$version = Environment::getIndexVersion(); $version = Environment::getIndexVersion();
$this->assertEquals(intval($rawVersion[0]), $version->getMajor()); $this->assertEquals((int)$rawVersion[0], $version->getMajor());
$this->assertEquals(intval($rawVersion[1]), $version->getMinor()); $this->assertEquals((int)$rawVersion[1], $version->getMinor());
$this->assertEquals(intval($rawVersion[2]), $version->getPatch()); $this->assertEquals((int)$rawVersion[2], $version->getPatch());
$this->assertEquals($strVersion, (string)$version); $this->assertEquals($strVersion, (string)$version);
} }