Skip to content

Commit

Permalink
Cleaning up PHPStan reported issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsizemore committed Aug 11, 2023
1 parent 2f97b6b commit 9697633
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 1.1.1 (2023-08-11)
* Version bump
* Cleaning up issues per PHPStan

### 1.1.0 (2023-06-24)
* Version bump
* Bumped PHP version requirement to 8.2
Expand Down
44 changes: 30 additions & 14 deletions src/Utility/Utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @author Eric Sizemore <[email protected]>
* @package Utility
* @link http://www.secondversion.com/
* @version 1.1.0
* @version 1.1.1
* @copyright (C) 2017 - 2023 Eric Sizemore
* @license The MIT License (MIT)
*/
Expand Down Expand Up @@ -54,7 +54,7 @@
* @author Eric Sizemore <[email protected]>
* @package Utility
* @link http://www.secondversion.com/
* @version 1.1.0
* @version 1.1.1
* @copyright (C) 2017 - 2023 Eric Sizemore
* @license The MIT License (MIT)
*
Expand Down Expand Up @@ -648,6 +648,11 @@ public static function lineCounter(string $directory, array $ignore = [], array
}

$content = file($val->getPath() . DIRECTORY_SEPARATOR . $val->getFilename(), $flags);

if (!$content) {
continue;
}
/** @var array<int, string>|\Countable $content **/
$content = count($content);

$lines[$val->getPath()][$val->getFilename()] = $content;
Expand Down Expand Up @@ -768,9 +773,9 @@ public static function directoryList(string $directory, array $ignore = []): arr
*
* Normalizes a file or directory path.
*
* @param string $path The file or directory path.
* @param string $separator The directory separator. Defaults to DIRECTORY_SEPARATOR.
* @return string The normalized file or directory path
* @param string $path The file or directory path.
* @param non-empty-string $separator The directory separator. Defaults to DIRECTORY_SEPARATOR.
* @return string The normalized file or directory path
*/
public static function normalizeFilePath(string $path, string $separator = DIRECTORY_SEPARATOR): string
{
Expand Down Expand Up @@ -870,11 +875,11 @@ public static function fileRead(string $file): string|false
* @param int $flags Bitwise OR'ed set of flags for file_put_contents. One or
* more of FILE_USE_INCLUDE_PATH, FILE_APPEND, LOCK_EX.
* {@link http://php.net/file_put_contents}
* @return string|false
* @return string|int<0, max>|false
*
* @throws InvalidArgumentException|RandomException
*/
public static function fileWrite(string $file, string $data = '', int $flags = 0): string|false
public static function fileWrite(string $file, string $data = '', int $flags = 0): string|false|int
{
// Sanity checks
if (!is_readable($file)) {
Expand Down Expand Up @@ -1118,6 +1123,7 @@ public static function getIpAddress(bool $trustProxy = false): string

if (!empty($ips)) {
foreach ($ips AS $val) {
/** @phpstan-ignore-next-line */
if (inet_ntop(inet_pton($val)) == $val AND static::isPublicIp($val)) {
$ip = $val;
break;
Expand Down Expand Up @@ -1289,9 +1295,9 @@ public static function isHttps(): bool
* Retrieve the current URL.
*
* @param bool $parse True to return the url as an array, false otherwise.
* @return string|array<mixed>
* @return mixed
*/
public static function currentUrl(bool $parse = false): string|array
public static function currentUrl(bool $parse = false): mixed
{
// Scheme
$url = (static::isHttps()) ? 'https://' : 'http://';
Expand Down Expand Up @@ -1513,11 +1519,21 @@ public static function timezoneInfo(string $timezone): array
throw new InvalidArgumentException($e->getMessage(), 0, $e);
}

$location = $tz->getLocation();

if ($location == false) {
$location = [
'country_code' => 'N/A',
'latitude' => 'N/A',
'longitude' => 'N/A'
];
}

$info = [
'offset' => $tz->getOffset(new DateTime('now', new DateTimeZone('GMT'))) / 3600,
'country' => $tz->getLocation()['country_code'],
'latitude' => $tz->getLocation()['latitude'],
'longitude' => $tz->getLocation()['longitude'],
'country' => $location['country_code'],
'latitude' => $location['latitude'],
'longitude' => $location['longitude'],
'dst' => $tz->getTransitions($now = time(), $now)[0]['isdst']
];
unset($tz);
Expand Down Expand Up @@ -1557,8 +1573,8 @@ public static function iniGet(string $option, bool $standardize = false): string

if ($standardize) {
$value = match (static::lower($option)) {
'yes', 'on', 'true', '1' => 1,
default => 0
'yes', 'on', 'true', '1' => '1',
default => '0'
};
}
return $value;
Expand Down

0 comments on commit 9697633

Please sign in to comment.