Skip to content

Commit

Permalink
Refactor code.
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone committed Aug 3, 2019
1 parent 0c7bee7 commit a42bad4
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 34 deletions.
20 changes: 10 additions & 10 deletions Concerns/Transformable.php
Expand Up @@ -84,18 +84,18 @@ public function setRequest($request)
*/
protected function merge($meta, array $options = []): array
{
if (is_array($meta) && empty($options)) {
if (\is_array($meta) && empty($options)) {
$options = $meta;
$meta = null;
}

$options = array_merge(['includes' => [], 'excludes' => []], $options);
$options = \array_merge(['includes' => [], 'excludes' => []], $options);

foreach ($options as $key => $value) {
$filtered = Arr::expand(array_flip($value));
$parent = Arr::get($this->options, is_null($meta) ? $key : "{$key}.{$meta}", []);
$filtered = Arr::expand(\array_flip($value));
$parent = Arr::get($this->options, \is_null($meta) ? $key : "{$key}.{$meta}", []);

$options[$key] = array_keys(Arr::dot(array_merge_recursive($filtered, $parent)));
$options[$key] = \array_keys(Arr::dot(\array_merge_recursive($filtered, $parent)));
}

return $options;
Expand All @@ -120,13 +120,13 @@ protected function transformByMeta(string $meta, array $data, ...$parameters): a
}

foreach ($types as $type => $index) {
if (is_array($type)) {
if (\is_array($type)) {
continue;
}

$method = $name.Str::studly($type);

if (method_exists($this, $method)) {
if (\method_exists($this, $method)) {
$data = $this->{$method}($data, ...$parameters);
}
}
Expand All @@ -145,10 +145,10 @@ protected function filterMetaType(string $name): void
{
$types = $this->options[$name] ?? $this->getRequest()->input($name);

if (is_string($types)) {
$types = explode(',', $types);
if (\is_string($types)) {
$types = \explode(',', $types);
}

$this->options[$name] = is_array($types) ? Arr::expand(array_flip($types)) : [];
$this->options[$name] = \is_array($types) ? Arr::expand(\array_flip($types)) : [];
}
}
2 changes: 1 addition & 1 deletion FormRequest.php
Expand Up @@ -51,7 +51,7 @@ protected function setupValidationScenario()
'DELETE' => 'destroy',
];

if (in_array($current, $available)) {
if (\in_array($current, $available)) {
$this->onValidationScenario($available[$current]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion HashIdServiceProvider.php
Expand Up @@ -22,7 +22,7 @@ class HashIdServiceProvider extends ServiceProvider
*/
public function register()
{
$this->app->singleton('orchestra.hashid', function (Application $app) {
$this->app->singleton('orchestra.hashid', static function (Application $app) {
return new Hashids($app->make('config')->get('app.key'));
});
}
Expand Down
2 changes: 1 addition & 1 deletion Middleware/NotModified.php
Expand Up @@ -19,7 +19,7 @@ public function handle($request, Closure $next)
$response = $next($request);

if (! $response->headers->has('Etag')) {
$response->setEtag(md5($response->getContent()));
$response->setEtag(\md5($response->getContent()));
}

$response->isNotModified($request);
Expand Down
2 changes: 1 addition & 1 deletion Middleware/RequireCsrfToken.php
Expand Up @@ -67,7 +67,7 @@ protected function tokensMatch($request)
$token = $this->encrypter->decrypt($header);
}

return hash_equals((string) $request->session()->token(), (string) $token);
return \hash_equals((string) $request->session()->token(), (string) $token);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Providers/VersionServiceProvider.php
Expand Up @@ -29,7 +29,7 @@ class VersionServiceProvider extends ServiceProvider
public function register()
{
$this->app->singleton('orchestra.http.version', function (Application $app) {
return tap(new VersionControl(), function ($version) {
return \tap(new VersionControl(), function ($version) {
$this->registerSupportedVersions($version);
});
});
Expand All @@ -48,7 +48,7 @@ protected function registerSupportedVersions(VersionControl $version): void
$version->addVersion($code, $namespace);
}

if (! is_null($this->defaultVersion)) {
if (! \is_null($this->defaultVersion)) {
$version->setDefaultVersion($this->defaultVersion);
}
}
Expand Down
10 changes: 3 additions & 7 deletions RouteManager.php
Expand Up @@ -38,13 +38,9 @@ abstract class RouteManager implements RouteManagerContract
*/
public function __construct(Application $app, ?RouteResolver $resolver = null)
{
if (is_null($resolver)) {
$resolver = new RouteResolver($app);
}

$this->app = $app;
$this->router = $this->resolveApplicationRouter($app);
$this->resolver = $resolver;
$this->resolver = $resolver instanceof RouteResolver ? $resolver : new RouteResolver($app);
}

/**
Expand Down Expand Up @@ -78,9 +74,9 @@ public function group(string $name, string $default, $attributes = [], Closure $
$attributes = [];
}

$attributes = array_merge($attributes, $route->group());
$attributes = \array_merge($attributes, $route->group());

if (! is_null($callback)) {
if (! \is_null($callback)) {
$this->router->group($attributes, $callback);
}

Expand Down
14 changes: 7 additions & 7 deletions RouteResolver.php
Expand Up @@ -108,8 +108,8 @@ public function locate(string $path, array $options = []): array

// split URI and query string, the route resolver should not worry
// about provided query string.
if (strpos($path, '?') !== false) {
list($path, $query) = explode('?', $path, 2);
if (\strpos($path, '?') !== false) {
list($path, $query) = \explode('?', $path, 2);
}

list($package, $route, $item) = with(new NamespacedItemResolver())->parseKey($path);
Expand Down Expand Up @@ -148,7 +148,7 @@ public function route(string $name, string $default = '/')
*/
public function mode(): string
{
if (is_null($this->status)) {
if (\is_null($this->status)) {
return 'normal';
}

Expand Down Expand Up @@ -189,7 +189,7 @@ public function to(string $path, array $options = []): string
*/
protected function generateRouteByName(string $name, string $default)
{
if (is_null($this->extension)) {
if (\is_null($this->extension)) {
return $default;
}

Expand All @@ -216,7 +216,7 @@ protected function prepareValidRoute(string $route, ?string $item, string $query
$appends['_token'] = $this->getCsrfToken();
}

if (! in_array($mode, ['normal'])) {
if (! \in_array($mode, ['normal'])) {
$appends['_mode'] = $mode;
}

Expand All @@ -240,7 +240,7 @@ protected function prepareValidRoute(string $route, ?string $item, string $query
protected function prepareHttpQueryString(string $query, array $appends = []): string
{
if (! empty($appends)) {
$query .= (! empty($query) ? '&' : '').http_build_query($appends);
$query .= (! empty($query) ? '&' : '').\http_build_query($appends);
}

return $query;
Expand All @@ -253,7 +253,7 @@ protected function prepareHttpQueryString(string $query, array $appends = []): s
*/
protected function getCsrfToken(): ?string
{
if (is_null($this->csrfToken)) {
if (\is_null($this->csrfToken)) {
$this->csrfToken = $this->app->make('session')->token();
}

Expand Down
8 changes: 4 additions & 4 deletions VersionControl.php
Expand Up @@ -51,7 +51,7 @@ public function addVersion(string $code, string $namespace, bool $default = fals
*/
public function setDefaultVersion(string $code)
{
if (! array_key_exists($code, $this->supportedVersions)) {
if (! \array_key_exists($code, $this->supportedVersions)) {
throw new InvalidArgumentException("Unable to set [{$code}] as default version!");
}

Expand All @@ -72,12 +72,12 @@ public function setDefaultVersion(string $code)
*/
public function resolve(string $namespace, string $version, string $name): string
{
$class = str_replace('.', '\\', $name);
$class = \str_replace('.', '\\', $name);

if (! array_key_exists($version, $this->supportedVersions)) {
if (! \array_key_exists($version, $this->supportedVersions)) {
$version = $this->defaultVersion;
}

return sprintf('%s\%s\%s\%s', $namespace, $this->supportedVersions[$version], $class);
return \sprintf('%s\%s\%s\%s', $namespace, $this->supportedVersions[$version], $class);
}
}

0 comments on commit a42bad4

Please sign in to comment.