diff --git a/.php_cs b/.php_cs index 4176509..8e0274f 100644 --- a/.php_cs +++ b/.php_cs @@ -10,6 +10,7 @@ return PhpCsFixer\Config::create() '@Symfony' => true, 'array_syntax' => ['syntax' => 'short'], 'binary_operator_spaces' => ['align_double_arrow' => false, 'align_equals' => false], + 'native_function_invocation' => ['include' => ['@compiler_optimized'], 'scope' => 'namespaced', 'strict' => true], 'no_extra_blank_lines' => false, 'no_empty_comment' => false, 'no_extra_consecutive_blank_lines' => false, diff --git a/src/Providers/CommandServiceProvider.php b/src/Providers/CommandServiceProvider.php index 43ca021..df19663 100644 --- a/src/Providers/CommandServiceProvider.php +++ b/src/Providers/CommandServiceProvider.php @@ -28,13 +28,13 @@ abstract class CommandServiceProvider extends BaseServiceProvider implements Def */ public function register() { - foreach (\array_keys($this->commands) as $command) { + foreach (array_keys($this->commands) as $command) { $method = "register{$command}Command"; $this->{$method}(); } - $this->commands(\array_values($this->commands)); + $this->commands(array_values($this->commands)); } /** @@ -44,6 +44,6 @@ public function register() */ public function provides() { - return \array_merge(\array_values($this->commands), $this->provides); + return array_merge(array_values($this->commands), $this->provides); } } diff --git a/src/Providers/Concerns/DiscoverableEventProvider.php b/src/Providers/Concerns/DiscoverableEventProvider.php index e4e2d90..eb6c808 100644 --- a/src/Providers/Concerns/DiscoverableEventProvider.php +++ b/src/Providers/Concerns/DiscoverableEventProvider.php @@ -44,7 +44,7 @@ public function discoverEvents() return Collection::make($this->discoverEventsWithin()) ->reduce(static function ($discovered, $directory) use ($basePath) { - return \array_merge_recursive( + return array_merge_recursive( $discovered, DiscoverEvents::within($directory, $basePath) ); diff --git a/src/Providers/Concerns/EventProvider.php b/src/Providers/Concerns/EventProvider.php index 59bd4ca..2e5f362 100644 --- a/src/Providers/Concerns/EventProvider.php +++ b/src/Providers/Concerns/EventProvider.php @@ -15,13 +15,13 @@ trait EventProvider */ public function registerEventListeners(DispatcherContract $dispatcher): void { - $events = \array_merge_recursive( - (\method_exists($this, 'discoveredEvents') ? $this->discoveredEvents() : []), + $events = array_merge_recursive( + (method_exists($this, 'discoveredEvents') ? $this->discoveredEvents() : []), $this->listens() ); foreach ($events as $event => $listeners) { - foreach (\array_unique($listeners) as $listener) { + foreach (array_unique($listeners) as $listener) { $dispatcher->listen($event, $listener); } } diff --git a/src/Providers/Concerns/PackageProvider.php b/src/Providers/Concerns/PackageProvider.php index 9ed6914..caabe35 100644 --- a/src/Providers/Concerns/PackageProvider.php +++ b/src/Providers/Concerns/PackageProvider.php @@ -115,7 +115,7 @@ public function guessPackagePath(): string { $path = (new ReflectionClass($this))->getFileName(); - return \realpath(\dirname($path).'/../../'); + return realpath(\dirname($path).'/../../'); } /** @@ -129,7 +129,7 @@ public function guessPackagePath(): string protected function getPackageNamespace(string $package, string $namespace): string { if (\is_null($namespace)) { - [, $namespace] = \explode('/', $package); + [, $namespace] = explode('/', $package); } return $namespace; @@ -144,7 +144,7 @@ protected function getPackageNamespace(string $package, string $namespace): stri */ protected function getAppViewPaths(string $package): array { - return \array_map(static function ($path) use ($package) { + return array_map(static function ($path) use ($package) { return "{$path}/packages/{$package}"; }, $this->app->make('config')->get('view.paths', [])); } diff --git a/src/Providers/ServiceProvider.php b/src/Providers/ServiceProvider.php index 2178452..4ce25e1 100644 --- a/src/Providers/ServiceProvider.php +++ b/src/Providers/ServiceProvider.php @@ -18,7 +18,7 @@ abstract class ServiceProvider extends BaseServiceProvider */ protected function loadFactoriesFrom($paths) { - if (\method_exists($this->app, 'runningUnitTests') && $this->app->runningUnitTests()) { + if (method_exists($this->app, 'runningUnitTests') && $this->app->runningUnitTests()) { $this->callAfterResolving(EloquentFactory::class, function ($factory) use ($paths) { foreach ((array) $paths as $path) { $factory->load($path); diff --git a/src/Support/Collection.php b/src/Support/Collection.php index d481c26..f121172 100644 --- a/src/Support/Collection.php +++ b/src/Support/Collection.php @@ -13,12 +13,12 @@ class Collection extends BaseCollection implements Csvable, Transformable */ public function toCsv(): string { - \ob_start(); + ob_start(); $stream = $this->streamCsv(); - \fclose($stream); + fclose($stream); - return \ob_get_clean(); + return ob_get_clean(); } /** @@ -32,12 +32,12 @@ public function streamCsv() $enclosure = '"'; $header = $this->resolveCsvHeader(); - $stream = \fopen('php://output', 'r+'); + $stream = fopen('php://output', 'r+'); - \fputcsv($stream, $header, $delimiter, $enclosure); + fputcsv($stream, $header, $delimiter, $enclosure); foreach ($this->items as $key => $item) { - \fputcsv($stream, Arr::dot($item), $delimiter, $enclosure); + fputcsv($stream, Arr::dot($item), $delimiter, $enclosure); } return $stream; @@ -54,7 +54,7 @@ protected function resolveCsvHeader(): array if (! $this->isEmpty()) { $single = $this->first(); - $header = \array_keys(Arr::dot($single)); + $header = array_keys(Arr::dot($single)); } return $header; diff --git a/src/Support/Concerns/DataContainer.php b/src/Support/Concerns/DataContainer.php index 791b2ea..26208ce 100644 --- a/src/Support/Concerns/DataContainer.php +++ b/src/Support/Concerns/DataContainer.php @@ -76,7 +76,7 @@ public function secureGet(string $key, $default = null) */ public function set(string $key, $value = null) { - return Arr::set($this->items, $key, \value($value)); + return Arr::set($this->items, $key, value($value)); } /** @@ -123,7 +123,7 @@ public function forget(string $key): bool { $items = $this->items; - \array_push($this->removedItems, $key); + array_push($this->removedItems, $key); Arr::forget($items, $key); $this->items = $items; diff --git a/src/Support/Concerns/Descendible.php b/src/Support/Concerns/Descendible.php index 0f4c017..eadf7a3 100644 --- a/src/Support/Concerns/Descendible.php +++ b/src/Support/Concerns/Descendible.php @@ -20,8 +20,8 @@ protected function descendants(array $array, ?string $key = null) return $array; } - $keys = \explode('.', $key); - $first = \array_shift($keys); + $keys = explode('.', $key); + $first = array_shift($keys); if (! isset($array[$first])) { return null; diff --git a/src/Support/Concerns/Observable.php b/src/Support/Concerns/Observable.php index ce7ecf2..a6b38e9 100644 --- a/src/Support/Concerns/Observable.php +++ b/src/Support/Concerns/Observable.php @@ -27,7 +27,7 @@ public static function observe($class): void $className = \get_class($class); foreach ($instance->getObservableEvents() as $event) { - if (\method_exists($class, $event)) { + if (method_exists($class, $event)) { static::registerObservableEvent($event, "{$className}@{$event}"); } } diff --git a/src/Support/Concerns/Uploadable.php b/src/Support/Concerns/Uploadable.php index 65e4680..a1fdd50 100644 --- a/src/Support/Concerns/Uploadable.php +++ b/src/Support/Concerns/Uploadable.php @@ -46,6 +46,6 @@ protected function getUploadedFilename(UploadedFile $file): string { $extension = $file->getClientOriginalExtension(); - return \sprintf('%s.%s', Str::random(10), $extension); + return sprintf('%s.%s', Str::random(10), $extension); } } diff --git a/src/Support/Concerns/Validation.php b/src/Support/Concerns/Validation.php index d3e2f96..0cbf1e2 100644 --- a/src/Support/Concerns/Validation.php +++ b/src/Support/Concerns/Validation.php @@ -38,7 +38,7 @@ final public function onValidationScenario(string $scenario, array $parameters = { [$on, $extend] = $this->getValidationSchemasName($scenario); - $this->validationScenarios = \compact('on', 'extend', 'parameters'); + $this->validationScenarios = compact('on', 'extend', 'parameters'); return $this; } @@ -52,7 +52,7 @@ final public function onValidationScenario(string $scenario, array $parameters = */ final public function bindToValidation(array $bindings): self { - $this->validationBindings = \array_merge($this->validationBindings, $bindings); + $this->validationBindings = array_merge($this->validationBindings, $bindings); return $this; } @@ -78,7 +78,7 @@ final public function runValidation($request, array $phrases = [], $events = []) [$rules, $phrases] = $this->runValidationEvents($events, $phrases); - return \tap(Validator::make($input, $rules, $phrases), function (ValidatorContract $validator) { + return tap(Validator::make($input, $rules, $phrases), function (ValidatorContract $validator) { $this->runExtendedScenario($validator); }); } @@ -144,12 +144,12 @@ final protected function runExtendedScenario(ValidatorContract $validator): void final protected function runValidationEvents($events, array $phrases): array { // Merge all the events. - $events = \array_merge($this->getValidationEvents(), Arr::wrap($events)); + $events = array_merge($this->getValidationEvents(), Arr::wrap($events)); // Convert rules array to Fluent, in order to pass it by references // in all event listening to this validation. $rules = new Fluent($this->getBindedRules()); - $phrases = new Fluent(\array_merge($this->getValidationPhrases(), $phrases)); + $phrases = new Fluent(array_merge($this->getValidationPhrases(), $phrases)); foreach ((array) $events as $event) { Event::dispatch($event, [&$rules, &$phrases]); @@ -206,8 +206,8 @@ protected function getValidationSchemasName(string $scenario): array $extend = "extend{$scenario}"; return [ - \method_exists($this, $on) ? $on : null, - \method_exists($this, $extend) ? $extend : null, + method_exists($this, $on) ? $on : null, + method_exists($this, $extend) ? $extend : null, ]; } } diff --git a/src/Support/Keyword.php b/src/Support/Keyword.php index 76a4cde..0b2bf8e 100644 --- a/src/Support/Keyword.php +++ b/src/Support/Keyword.php @@ -28,7 +28,7 @@ public function __construct($value) $this->value = $value; if (\is_string($value)) { - $this->slug = \trim(Str::slug($value, '-')); + $this->slug = trim(Str::slug($value, '-')); } } @@ -78,10 +78,10 @@ public function getSlug(): ?string public function searchIn(array $items = []) { if (\is_null($slug = $this->slug)) { - return \array_search($this->value, $items); + return array_search($this->value, $items); } - return \array_search($slug, $items); + return array_search($slug, $items); } /** diff --git a/src/Support/Manager.php b/src/Support/Manager.php index 787d624..241149b 100644 --- a/src/Support/Manager.php +++ b/src/Support/Manager.php @@ -45,7 +45,7 @@ protected function createDriver($driverName) // creator Closure to create it. if (isset($this->customCreators[$driver])) { return $this->callCustomCreator($driverName); - } elseif (\method_exists($this, $method)) { + } elseif (method_exists($this, $method)) { return $this->{$method}($name); } @@ -75,11 +75,11 @@ protected function callCustomCreator($driverName) */ protected function getDriverName(string $driverName): array { - if (false === \strpos($driverName, '.')) { + if (false === strpos($driverName, '.')) { $driverName = "{$driverName}.default"; } - [$driver, $name] = \explode('.', $driverName, 2); + [$driver, $name] = explode('.', $driverName, 2); $this->checkNameIsNotBlacklisted($name); diff --git a/src/Support/Nesty.php b/src/Support/Nesty.php index 6cb0527..90cf8c0 100644 --- a/src/Support/Nesty.php +++ b/src/Support/Nesty.php @@ -42,7 +42,7 @@ protected function toFluent($id): Fluent $defaults = $this->config['defaults'] ?? []; $class = $this->config['fluent'] ?? Fluent::class; - return new $class(\array_merge($defaults, [ + return new $class(array_merge($defaults, [ 'id' => $id, 'childs' => [], ])); @@ -60,8 +60,8 @@ protected function addBefore(string $id, string $before): Fluent { $items = []; $item = $this->toFluent($id); - $keys = \array_keys($this->items); - $position = \array_search($before, $keys); + $keys = array_keys($this->items); + $position = array_search($before, $keys); if ($position === false) { return $this->addParent($id); @@ -92,8 +92,8 @@ protected function addAfter(string $id, string $after): Fluent { $items = []; $item = $this->toFluent($id); - $keys = \array_keys($this->items); - $position = \array_search($after, $keys); + $keys = array_keys($this->items); + $position = array_search($after, $keys); if ($position === false) { return $this->addParent($id); @@ -161,9 +161,9 @@ protected function addParent(string $id): Fluent */ public function add(string $id, string $location = '#'): ?Fluent { - if ($location === '<' && count($keys = array_keys($this->items)) > 0) { + if ($location === '<' && \count($keys = array_keys($this->items)) > 0) { return $this->addBefore($id, $keys[0]); - } elseif (\preg_match('/^(<|>|\^):(.+)$/', $location, $matches) && count($matches) >= 3) { + } elseif (preg_match('/^(<|>|\^):(.+)$/', $location, $matches) && \count($matches) >= 3) { return $this->pickTraverseFromMatchedExpression($id, $matches[1], $matches[2]); } @@ -201,9 +201,9 @@ protected function pickTraverseFromMatchedExpression(string $id, string $key, st */ public function has(string $key): bool { - $key = \implode('.childs.', \explode('.', $key)); + $key = implode('.childs.', explode('.', $key)); - return ! \is_null(\data_get($this->items, $key)); + return ! \is_null(data_get($this->items, $key)); } /** diff --git a/src/Support/Serializer.php b/src/Support/Serializer.php index 48bcee1..661db95 100644 --- a/src/Support/Serializer.php +++ b/src/Support/Serializer.php @@ -23,7 +23,7 @@ abstract class Serializer */ public function __invoke(...$parameters) { - if (\method_exists($this, 'serialize')) { + if (method_exists($this, 'serialize')) { return $this->serialize(...$parameters); } diff --git a/src/Support/Str.php b/src/Support/Str.php index 8cf48fe..51b0c02 100644 --- a/src/Support/Str.php +++ b/src/Support/Str.php @@ -31,7 +31,7 @@ class Str extends BaseStr */ public static function humanize(string $text): string { - $text = \str_replace(['-', '_'], ' ', $text); + $text = str_replace(['-', '_'], ' ', $text); return Stringy::create($text)->humanize()->titleize(); } @@ -55,11 +55,11 @@ public static function translate( $replacements = static::prepareBinding($replacements, $prefix, $suffix); $filter = static function ($text) use ($replacements) { - return \strtr($text, $replacements); + return strtr($text, $replacements); }; if (\is_array($text)) { - $text = \array_map($filter, $text); + $text = array_map($filter, $text); } else { $text = $filter($text); } @@ -87,7 +87,7 @@ public static function searchable(string $text, string $wildcard = '*', string $ ]; } - return [\str_replace($wildcard, $replacement, $text)]; + return [str_replace($wildcard, $replacement, $text)]; } /** @@ -103,7 +103,7 @@ public static function validateColumnName(?string $column): bool return false; } - if (! \preg_match(self::VALID_COLUMN_NAME_REGEX, $column)) { + if (! preg_match(self::VALID_COLUMN_NAME_REGEX, $column)) { return false; } @@ -128,17 +128,17 @@ public static function streamGetContents($data): string } // Get the content from stream. - $hex = \stream_get_contents($data); + $hex = stream_get_contents($data); // For some reason hex would always start with 'x' and if we // don't filter out this char, it would mess up hex to string // conversion. - if (\preg_match('/^x(.*)$/', $hex, $matches)) { + if (preg_match('/^x(.*)$/', $hex, $matches)) { $hex = $matches[1]; } // Check if it's actually a hex string before trying to convert. - if (! \ctype_xdigit($hex)) { + if (! ctype_xdigit($hex)) { return $hex; } @@ -158,7 +158,7 @@ protected static function fromHex(string $hex): string // Convert hex to string. for ($i = 0; $i < \strlen($hex) - 1; $i += 2) { - $data .= \chr(\hexdec($hex[$i].$hex[$i + 1])); + $data .= \chr(hexdec($hex[$i].$hex[$i + 1])); } return $data; @@ -182,7 +182,7 @@ protected static function prepareBinding( $bindings = []; foreach ($replacements as $key => $value) { - if (\is_scalar($value)) { + if (is_scalar($value)) { $bindings["{$prefix}{$key}{$suffix}"] = $value; } } diff --git a/src/Support/Timezone.php b/src/Support/Timezone.php index ccad964..811776e 100644 --- a/src/Support/Timezone.php +++ b/src/Support/Timezone.php @@ -614,12 +614,12 @@ public static function whereHourInUtc(int $hourInUtc): Collection $where = ['UTC', 'GMT']; if ($hourInUtc > 12) { - $offsetHour = \str_pad((24 - $hourInUtc), 2, '0', STR_PAD_LEFT); - $beforeOffsetHour = \str_pad(((24 - $hourInUtc) - 1), 2, '0', STR_PAD_LEFT); + $offsetHour = str_pad((24 - $hourInUtc), 2, '0', STR_PAD_LEFT); + $beforeOffsetHour = str_pad(((24 - $hourInUtc) - 1), 2, '0', STR_PAD_LEFT); $where = ["+{$offsetHour}00", "+{$beforeOffsetHour}30", "+{$beforeOffsetHour}45"]; } elseif ($hourInUtc > 0) { - $offsetHour = \str_pad($hourInUtc, 2, '0', STR_PAD_LEFT); + $offsetHour = str_pad($hourInUtc, 2, '0', STR_PAD_LEFT); $where = ["-{$offsetHour}00", "-{$offsetHour}30", "-{$offsetHour}45"]; } diff --git a/src/Support/Validator.php b/src/Support/Validator.php index 2b0a4d2..07e8004 100644 --- a/src/Support/Validator.php +++ b/src/Support/Validator.php @@ -2,10 +2,7 @@ namespace Orchestra\Support; -use Illuminate\Contracts\Events\Dispatcher; -use Illuminate\Contracts\Validation\Factory; use Illuminate\Contracts\Validation\Validator as ValidatorContract; -use Illuminate\Http\Request; abstract class Validator { @@ -73,7 +70,7 @@ public function bind(array $bindings) */ public function listen($events) { - $this->localEvents = \array_merge($this->localEvents, Arr::wrap($events)); + $this->localEvents = array_merge($this->localEvents, Arr::wrap($events)); return $this; } diff --git a/tests/Providers/MiddlewareServiceProviderTest.php b/tests/Providers/MiddlewareServiceProviderTest.php index 85745e3..284aad5 100644 --- a/tests/Providers/MiddlewareServiceProviderTest.php +++ b/tests/Providers/MiddlewareServiceProviderTest.php @@ -15,7 +15,7 @@ public function instance_has_proper_signature() { $stub = new StubMiddlewareProvider($this->app); - $this->assertContains(MiddlewareProvider::class, class_uses_recursive(get_class($stub))); + $this->assertContains(MiddlewareProvider::class, class_uses_recursive(\get_class($stub))); } /** @test */ @@ -23,7 +23,7 @@ public function it_can_be_registered() { $stub = new StubMiddlewareProvider($this->app); - $this->assertContains(MiddlewareProvider::class, class_uses_recursive(get_class($stub))); + $this->assertContains(MiddlewareProvider::class, class_uses_recursive(\get_class($stub))); $this->assertNull($stub->register()); } diff --git a/tests/Providers/ServiceProviderTest.php b/tests/Providers/ServiceProviderTest.php index 46b7bb3..c04a0f0 100644 --- a/tests/Providers/ServiceProviderTest.php +++ b/tests/Providers/ServiceProviderTest.php @@ -18,6 +18,6 @@ public function register() } }; - $this->assertContains(PackageProvider::class, class_uses_recursive(get_class($stub))); + $this->assertContains(PackageProvider::class, class_uses_recursive(\get_class($stub))); } } diff --git a/tests/ValidatorTest.php b/tests/ValidatorTest.php index 04e502b..08c0e7b 100644 --- a/tests/ValidatorTest.php +++ b/tests/ValidatorTest.php @@ -2,10 +2,8 @@ namespace Orchestra\Support\Tests; -use Illuminate\Support\Facades\Event; -use Illuminate\Support\Facades\Validator; -use Illuminate\Contracts\Validation\Factory as ValidationFactory; use Illuminate\Contracts\Validation\Validator as ValidatorContract; +use Illuminate\Support\Facades\Event; use Mockery as m; use Orchestra\Testbench\TestCase;