Skip to content

Commit

Permalink
Bump hyperf/utils and clear useless codes (#144)
Browse files Browse the repository at this point in the history
* Bump `hyperf/utils` and clear useless codes

* Remove useless code and rename

* Remove test cases

---------

Co-authored-by: Deeka Wong <[email protected]>
  • Loading branch information
huangdijia and huangdijia authored Feb 27, 2023
1 parent 516f2c4 commit 8b4257c
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 134 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"require": {
"hyperf/macroable": "~3.0.0",
"hyperf/utils": "~3.0.0",
"hyperf/utils": "~3.0.8",
"nesbot/carbon": "^2.0"
},
"autoload": {
Expand Down
47 changes: 0 additions & 47 deletions output/Hyperf/Utils/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,6 @@ public static function isJson($value)
{
}

/**
* Determine if a given string is a valid ULID.
*
* @param string $value
* @return bool
*/
public static function isUlid($value)
{
}

/**
* Determine if a given string is a valid UUID.
*
* @param string $value
* @return bool
*/
public static function isUuid($value)
{
}

/**
* Make a string's first character lowercase.
*
Expand Down Expand Up @@ -133,15 +113,6 @@ public static function inlineMarkdown($string, array $options = [])
{
}

/**
* Generate a time-ordered UUID (version 7).
*
* @return \Ramsey\Uuid\UuidInterface
*/
public static function orderedUuid()
{
}

/**
* Generate a random, secure password.
*
Expand Down Expand Up @@ -234,24 +205,6 @@ public static function ucsplit($string)
{
}

/**
* Generate a ULID.
*
* @return \Symfony\Component\Uid\Ulid
*/
public static function ulid()
{
}

/**
* Generate a UUID (version 4).
*
* @return \Ramsey\Uuid\UuidInterface
*/
public static function uuid()
{
}

/**
* Get the number of words a string contains.
*
Expand Down
20 changes: 11 additions & 9 deletions output/Hyperf/Utils/Stringable.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,6 @@ public function isJson()
{
}

/**
* Determine if a given string is a valid UUID.
*
* @return bool
*/
public function isUuid()
{
}

/**
* Make a string's first character lowercase.
*
Expand Down Expand Up @@ -275,6 +266,17 @@ public function whenIsAscii($callback, $default = null)
{
}

/**
* Execute the given callback if the string is a valid ULID.
*
* @param callable $callback
* @param null|callable $default
* @return static
*/
public function whenIsUlid($callback, $default = null)
{
}

/**
* Execute the given callback if the string is a valid UUID.
*
Expand Down
2 changes: 1 addition & 1 deletion src/ArrMacros.php → src/ArrMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* @mixin Arr
*/
class ArrMacros
class ArrMixin
{
public function isList()
{
Expand Down
2 changes: 1 addition & 1 deletion src/CollectionMacros.php → src/CollectionMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* @mixin Collection
*/
class CollectionMacros
class CollectionMixin
{
public function doesntContain()
{
Expand Down
20 changes: 10 additions & 10 deletions src/Listener/RegisterMixinListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
*/
namespace FriendsOfHyperf\Macros\Listener;

use FriendsOfHyperf\Macros\ArrMacros;
use FriendsOfHyperf\Macros\CollectionMacros;
use FriendsOfHyperf\Macros\RequestMacros;
use FriendsOfHyperf\Macros\StringableMacros;
use FriendsOfHyperf\Macros\StrMacros;
use FriendsOfHyperf\Macros\ArrMixin;
use FriendsOfHyperf\Macros\CollectionMixin;
use FriendsOfHyperf\Macros\RequestMixin;
use FriendsOfHyperf\Macros\StringableMixin;
use FriendsOfHyperf\Macros\StrMixin;
use Hyperf\Event\Contract\ListenerInterface;
use Hyperf\Framework\Event\BootApplication;
use Hyperf\HttpServer\Request;
Expand All @@ -37,10 +37,10 @@ public function listen(): array
*/
public function process(object $event): void
{
Arr::mixin(new ArrMacros());
Collection::mixin(new CollectionMacros());
Request::mixin(new RequestMacros());
Str::mixin(new StrMacros());
Stringable::mixin(new StringableMacros());
Arr::mixin(new ArrMixin());
Collection::mixin(new CollectionMixin());
Request::mixin(new RequestMixin());
Str::mixin(new StrMixin());
Stringable::mixin(new StringableMixin());
}
}
2 changes: 1 addition & 1 deletion src/RequestMacros.php → src/RequestMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* @mixin Request
*/
class RequestMacros
class RequestMixin
{
public function allFiles()
{
Expand Down
52 changes: 1 addition & 51 deletions src/StrMacros.php → src/StrMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@
use League\CommonMark\Extension\InlinesOnly\InlinesOnlyExtension;
use League\CommonMark\GithubFlavoredMarkdownConverter;
use League\CommonMark\MarkdownConverter;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\Uuid as RamseyUuid;
use Symfony\Component\Uid\Ulid as SymfonyUlid;
use voku\helper\ASCII;

/**
* @mixin Str
*/
class StrMacros
class StrMixin
{
public function betweenFirst()
{
Expand Down Expand Up @@ -154,36 +151,6 @@ public function isJson()
};
}

public function isUlid()
{
return function ($value) {
if (! is_string($value)) {
return false;
}

if (strlen($value) !== 26) {
return false;
}

if (strspn($value, '0123456789ABCDEFGHJKMNPQRSTVWXYZabcdefghjkmnpqrstvwxyz') !== 26) {
return false;
}

return $value[0] <= '7';
};
}

public function isUuid()
{
return function ($value) {
if (! is_string($value)) {
return false;
}

return preg_match('/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iD', $value) > 0;
};
}

public function lcfirst()
{
return fn ($string) => Str::lower(Str::substr($string, 0, 1)) . Str::substr($string, 1);
Expand All @@ -194,11 +161,6 @@ public function markdown()
return fn ($string, array $options = []) => (string) (new GithubFlavoredMarkdownConverter($options))->convert($string);
}

public function orderedUuid()
{
return fn () => Uuid::uuid7();
}

public function password()
{
return fn ($length = 32, $letters = true, $numbers = true, $symbols = true, $spaces = false) => (new Collection())
Expand Down Expand Up @@ -258,18 +220,6 @@ public function ucsplit()
return fn ($string) => preg_split('/(?=\p{Lu})/u', $string, -1, PREG_SPLIT_NO_EMPTY);
}

public function ulid()
{
return fn () => new SymfonyUlid();
}

public function uuid()
{
return fn () => UuidContainer::$uuidFactory
? call_user_func(UuidContainer::$uuidFactory)
: RamseyUuid::uuid4();
}

public function wordCount()
{
return fn ($string) => str_word_count($string);
Expand Down
14 changes: 1 addition & 13 deletions src/StringableMacros.php → src/StringableMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* @mixin Stringable
*/
class StringableMacros
class StringableMixin
{
public function betweenFirst()
{
Expand Down Expand Up @@ -61,18 +61,6 @@ public function isJson()
return fn () => Str::isJson($this->value);
}

public function isUlid()
{
/* @phpstan-ignore-next-line */
return fn () => Str::isUlid($this->value);
}

public function isUuid()
{
/* @phpstan-ignore-next-line */
return fn () => Str::isUuid($this->value);
}

public function lcfirst()
{
/* @phpstan-ignore-next-line */
Expand Down

0 comments on commit 8b4257c

Please sign in to comment.