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

View file

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

View file

@ -1,7 +1,7 @@
<?php
// AcceptEncodingHeader.php
// Created: 2022-02-14
// Updated: 2022-02-27
// Updated: 2023-01-01
namespace Index\Http\Headers;
@ -53,7 +53,7 @@ class AcceptEncodingHeader {
foreach($part as $param) {
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;
}
}

View file

@ -1,7 +1,7 @@
<?php
// AcceptLanguageHeader.php
// Created: 2022-02-14
// Updated: 2022-02-27
// Updated: 2023-01-01
namespace Index\Http\Headers;
@ -54,7 +54,7 @@ class AcceptLanguageHeader {
foreach($part as $param) {
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;
}
}

View file

@ -1,7 +1,7 @@
<?php
// AcceptTransferEncodingHeader.php
// Created: 2022-02-14
// Updated: 2022-02-27
// Updated: 2023-01-01
namespace Index\Http\Headers;
@ -53,7 +53,7 @@ class AcceptTransferEncodingHeader {
foreach($part as $param) {
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;
}
}

View file

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

View file

@ -1,7 +1,7 @@
<?php
// ExpectHeader.php
// Created: 2022-02-14
// Updated: 2022-02-14
// Updated: 2023-01-01
namespace Index\Http\Headers;
@ -26,6 +26,6 @@ class ExpectHeader {
public static function parse(HttpHeader $header): ExpectHeader {
$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
// HostHeader.php
// Created: 2022-02-14
// Updated: 2022-02-14
// Updated: 2023-01-01
namespace Index\Http\Headers;
@ -30,6 +30,6 @@ class HostHeader {
public static function parse(HttpHeader $header): HostHeader {
$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
// KeepAliveHeader.php
// Created: 2022-02-14
// Updated: 2022-02-15
// Updated: 2023-01-01
namespace Index\Http\Headers;
@ -31,9 +31,9 @@ class KeepAliveHeader {
foreach($params as $param) {
if(str_starts_with($param, 'timeout='))
$timeOut = intval(substr($param, 8));
$timeOut = (int)substr($param, 8);
elseif(str_starts_with($param, 'max='))
$max = intval(substr($param, 4));
$max = (int)substr($param, 4);
if($timeOut >= 0 && $max >= 0)
break;
}

View file

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

View file

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

View file

@ -1,7 +1,7 @@
<?php
// DnsEndPoint.php
// Created: 2021-05-02
// Updated: 2022-02-28
// Updated: 2023-01-01
namespace Index\Net;
@ -49,7 +49,7 @@ class DnsEndPoint extends EndPoint implements Stringable {
$parts = explode(':', $string);
if(count($parts) < 2)
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 {

View file

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

View file

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

View file

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

View file

@ -1,7 +1,7 @@
<?php
// XString.php
// Created: 2022-02-03
// Updated: 2022-02-27
// Updated: 2023-01-01
namespace Index;
@ -14,11 +14,11 @@ final class XString {
}
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 {
return floatval($value);
return (float)$value;
}
public static function escape(

View file

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