Skip to content

Commit

Permalink
Add Deprecations (#27)
Browse files Browse the repository at this point in the history
Co-authored-by: onairmarc <[email protected]>
  • Loading branch information
onairmarc and onairmarc authored Nov 6, 2024
1 parent af59354 commit 5adc6c9
Show file tree
Hide file tree
Showing 21 changed files with 67 additions and 61 deletions.
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ c10c3ac2613e54de290a9135afe024036174ef20
aef6f8b59ab2ff054b1a823efe242e0cb0cd1164
d521d82e9b14a5f411f3492529800c6b39f17740
11b88b5f8641574fc93d2a4f443aeaf819381c91
f74b50a0c5a93e2042dd0899f67dc0d77d9f37b2
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class DirectoryNotFoundException extends BaseException
public function __construct(?string $path = null)
{
if (is_null($path)) {
$msg = str_concat_space('Unable to locate directory on line', $this->line, 'in', $this->file);
$msg = "Unable to locate directory on line {$this->line} in {$this->file}";
} else {
$msg = str_concat_space('Unable to locate directory', $path, 'on line', $this->line, 'in', $this->file);
$msg = "Unable to locate directory {$path} on line {$this->line} in {$this->file}";
}

parent::__construct($msg, ExitCode::RESOURCE_UNAVAILABLE, $this->getPrevious());
Expand Down
4 changes: 2 additions & 2 deletions src/Exceptions/FilesystemExceptions/FileNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class FileNotFoundException extends BaseException
public function __construct(?string $path = null)
{
if (is_null($path)) {
$msg = str_concat_space('Unable to locate file on line', $this->line, 'in', $this->file);
$msg = "Unable to locate file on line {$this->line} in {$this->file}";
} else {
$msg = str_concat_space('Unable to locate file', $path, 'on line', $this->line, 'in', $this->file);
$msg = "Unable to locate file {$path} on line {$this->line} in {$this->file}";
}

parent::__construct($msg, ExitCode::RESOURCE_UNAVAILABLE, $this->getPrevious());
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/ImproperBooleanReturnedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct(bool $expected = true)
$actual = 'true';
}

$msg = str_concat_space('Improper boolean returned. Expected', $expect, 'but got', $actual);
$msg = "Improper boolean returned. Expected {$expect} but got {$actual}";

parent::__construct($msg, ExitCode::DATA_ERROR, $this->getPrevious());
}
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/NotImplementedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class NotImplementedException extends BaseException
{
public function __construct()
{
$msg = str_concat_space('Method is not implemented on line', $this->line, 'in', $this->file);
$msg = "Method is not implemented on line {$this->line} in {$this->file}";

parent::__construct($msg, ExitCode::RESOURCE_UNAVAILABLE, $this->getPrevious());
}
Expand Down
2 changes: 2 additions & 0 deletions src/ObjectHelpers/arr_helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
if (!function_exists('arr_to_short_syntax')) {
/**
* @throws ArgumentNullException
*
* @deprecated No Replacement
*/
function arr_to_short_syntax(array|string $value): array|string
{
Expand Down
19 changes: 16 additions & 3 deletions src/ObjectHelpers/dir_helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,43 @@
use EncoreDigitalGroup\StdLib\Objects\Directory;

if (!function_exists('dir_current')) {
/** @deprecated */
function dir_current(): string
{
return Directory::current();
}
}

if (!function_exists('dir_hash')) {
/** @experimental */
/**
* @experimental
*
* @deprecated
* */
function dir_hash(string $dir): string
{
return Directory::hash($dir);
}
}

if (!function_exists('dir_scan')) {
/** @experimental */
/**
* @experimental
*
* @deprecated
*/
function dir_scan(string $dir): array
{
return Directory::scan($dir);
}
}

if (!function_exists('dir_scan_recursive')) {
/** @experimental */
/**
* @experimental
*
* @deprecated
*/
function dir_scan_recursive(string $path): array
{
return Directory::scanRecursive($path);
Expand Down
12 changes: 10 additions & 2 deletions src/ObjectHelpers/file_helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,23 @@ function file_save_contents(string $path, mixed $data): void
}

if (!function_exists('file_copy')) {
/** @throws FileNotFoundException */
/**
* @throws FileNotFoundException
*
* @deprecated
*/
function file_copy(string $source, string $destination): void
{
File::copy($source, $destination);
}
}

if (!function_exists('file_delete')) {
/** @throws FileNotFoundException */
/**
* @throws FileNotFoundException
*
* @deprecated
*/
function file_delete(string $path): void
{
File::delete($path);
Expand Down
1 change: 1 addition & 0 deletions src/ObjectHelpers/num_helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use EncoreDigitalGroup\StdLib\Objects\Number;

if (!function_exists('num_to_int')) {
/** @deprecated */
function num_to_int(mixed $value): int
{
return Number::toInt($value);
Expand Down
2 changes: 0 additions & 2 deletions src/ObjectHelpers/php_function_helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

if (!function_exists('get_type')) {
/**
* @noinspection PhpMissingReturnTypeInspection
*
* @phpstan-ignore-next-line
*/
function get_type(mixed $value): string
Expand Down
13 changes: 11 additions & 2 deletions src/ObjectHelpers/str_helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,23 @@ function str_camel(string $string): string
}

if (!function_exists('str_concat')) {
/**@param array<string, string> ...$str */
/**
* @param array<string, string> ...$str
*
* @deprecated
*/
function str_concat(mixed ...$str): string
{
return Str::concat($str);
}
}

if (!function_exists('str_concat_space')) {
/**@param array<string, string> ...$str */
/**
* @param array<string, string> ...$str
*
* @deprecated
*/
function str_concat_space(mixed ...$str): string
{
return Str::concatSpace($str); //@phpstan-ignore-line
Expand Down Expand Up @@ -70,6 +78,7 @@ function str_lower(?string $str = null): ?string
}

if (!function_exists('str_max_length')) {
/** @deprecated use str_limit() instead. */
function str_max_length(string $str, ?int $length = null): string
{
return Str::maxLength($str, $length);
Expand Down
3 changes: 2 additions & 1 deletion src/ObjectHelpers/val_helpers.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?php

if (!function_exists('not_null')) {
/** @deprecated */
function not_null(mixed $value): bool
{
return !is_null($value);
}
}

if (!function_exists('val_not_null')) {
/** @deprecated Use not_null() instead. */
/** @deprecated */
function val_not_null(mixed $value): bool
{
return not_null($value);
Expand Down
19 changes: 11 additions & 8 deletions src/Objects/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@

namespace EncoreDigitalGroup\StdLib\Objects;

use EncoreDigitalGroup\StdLib\Exceptions\ArgumentNullException;
use EncoreDigitalGroup\StdLib\Exceptions\NullExceptions\ArgumentNullException;
use Illuminate\Support\Arr as ArraySupport;
use TypeError;

/**
* @api
*
* @internal
*/
/** @api */
class Arr extends ArraySupport
{
/** @deprecated use Arr::toShort() instead. */
public static function convertToShortSyntax(array|string $code): array|string
{
return static::toShort($code);
}

public static function toShort(array|string $code): array|string
{
// Regular expression to match long array syntax
$pattern = '/array\s*\(([^()]*(?:(?R)[^()]*)*)\)/m';
Expand All @@ -22,13 +24,14 @@ public static function convertToShortSyntax(array|string $code): array|string
$callback = function ($matches): string {
// Recursively convert nested arrays
$innerArray = $matches[1];
$convertedInnerArray = self::convertToShortSyntax($innerArray);
$convertedInnerArray = self::toShort($innerArray);

// Handle proper formatting of nested arrays
$convertedInnerArray = preg_replace('/\n\s*/', ' ', $convertedInnerArray);

if (!is_string($convertedInnerArray)) {
throw new TypeError(str_concat_space('Expected string, got ', get_type($convertedInnerArray)));
$type = get_type($convertedInnerArray);
throw new TypeError("Expected string, got {$type}");
}

return "[\n " . $convertedInnerArray . "\n]";
Expand Down
6 changes: 1 addition & 5 deletions src/Objects/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;

/**
* @api
*
* @internal
*/
/** @api */
class Directory
{
/**
Expand Down
6 changes: 1 addition & 5 deletions src/Objects/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@

use EncoreDigitalGroup\StdLib\Exceptions\FileNotFoundException;

/**
* @api
*
* @internal
*/
/** @api */
class File
{
/**
Expand Down
6 changes: 1 addition & 5 deletions src/Objects/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

namespace EncoreDigitalGroup\StdLib\Objects;

/**
* @api
*
* @internal
*/
/** @api */
class Json
{
/**
Expand Down
6 changes: 1 addition & 5 deletions src/Objects/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@

use Illuminate\Support\Number as NumberSupport;

/**
* @api
*
* @internal
*/
/** @api */
class Number extends NumberSupport
{
/**
Expand Down
6 changes: 1 addition & 5 deletions src/Objects/Php.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

namespace EncoreDigitalGroup\StdLib\Objects;

/**
* @api
*
* @internal
*/
/** @api */
class Php
{
/**
Expand Down
6 changes: 1 addition & 5 deletions src/Objects/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@

use Illuminate\Support\Str as StringSupport;

/**
* @api
*
* @internal
*/
/** @api */
class Str extends StringSupport
{
/**@param array<string, string> ...$str */
Expand Down
6 changes: 1 addition & 5 deletions src/Objects/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

namespace EncoreDigitalGroup\StdLib\Objects;

/**
* @api
*
* @internal
*/
/** @api */
class Url
{
public static function encode(mixed $data): string
Expand Down
2 changes: 0 additions & 2 deletions src/Objects/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
* @api
*
* @deprecated
*
* @internal
*/
#[Deprecated]
class Value
Expand Down

0 comments on commit 5adc6c9

Please sign in to comment.