Skip to content

Commit

Permalink
Remove some dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
tfirdaus committed Oct 10, 2024
1 parent 679b4b7 commit 0a4311f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
17 changes: 15 additions & 2 deletions app/Core/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
namespace Codex\Core;

use Adbar\Dot;
use Syntatis\Utils\Val;

use function count;
use function dot;
use function is_array;
use function is_string;
use function trim;

/** @internal This class should not be used directly, Developers should use the `Config` facade instead. */
final class Config
Expand Down Expand Up @@ -49,6 +52,16 @@ public function has(string $key): bool
*/
public function isBlank(string $key): bool
{
return Val::isBlank($this->dot->get($key));
$value = $this->dot->get($key);

if ($value === false || $value === null) {
return true;
}

if (is_string($value) && trim($value) === '') {
return true;
}

return is_array($value) && count($value) === 0;
}
}
10 changes: 8 additions & 2 deletions app/Foundation/Hooks/Support/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
use Codex\Foundation\Hooks\Filter;
use Codex\Foundation\Hooks\Hook;
use ReflectionClass;
use Syntatis\Utils\Str;

use function is_callable;
use function strlen;
use function strncmp;

/** @internal */
final class Parser implements Hookable
Expand Down Expand Up @@ -86,7 +87,12 @@ private function parseMethodAttrs(): void
continue;
}

if ($method->isConstructor() || $method->isDestructor() || Str::startsWith($method->getName(), '__')) {
if (
$method->isConstructor() ||
$method->isDestructor() ||
// Starts with __
strncmp($method->getName(), '__', strlen('__')) === 0
) {
continue;
}

Expand Down
12 changes: 6 additions & 6 deletions app/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
use Psr\Container\ContainerInterface;
use RecursiveDirectoryIterator;
use SplFileInfo;
use Syntatis\Utils\Val;

use function dirname;
use function is_dir;
use function is_file;
use function is_string;
use function is_subclass_of;
use function method_exists;
use function trim;

/**
* Orchastates the WordPress plugin lifecycle and define the required services.
Expand Down Expand Up @@ -232,7 +232,11 @@ private function registerCoreServices(): void
}
}

if (! isset($config['app']['name']) || Val::isBlank($config['app']['name'])) {
if (
! isset($config['app']['name']) ||
! is_string($config['app']['name']) ||
trim($config['app']['name']) === ''
) {
throw new InvalidArgumentException('The app "name" is required and cannot be empty.');
}

Expand All @@ -243,10 +247,6 @@ private function registerCoreServices(): void
$config = $container['config'];
$name = $config->get('app.name');

if (! is_string($name) || Val::isBlank($name)) {
throw new InvalidArgumentException('The app "name" is required and cannot be empty.');
}

return new App($name, $config);

Check failure on line 250 in app/Plugin.php

View workflow job for this annotation

GitHub Actions / test (7.4, 5.*)

Parameter #1 $name of class Codex\Core\App constructor expects string, mixed given.

Check failure on line 250 in app/Plugin.php

View workflow job for this annotation

GitHub Actions / test (8.0, 5.*)

Parameter #1 $name of class Codex\Core\App constructor expects string, mixed given.

Check failure on line 250 in app/Plugin.php

View workflow job for this annotation

GitHub Actions / test (8.0, 6.*)

Parameter #1 $name of class Codex\Core\App constructor expects string, mixed given.

Check failure on line 250 in app/Plugin.php

View workflow job for this annotation

GitHub Actions / test (8.1, 5.*)

Parameter #1 $name of class Codex\Core\App constructor expects string, mixed given.

Check failure on line 250 in app/Plugin.php

View workflow job for this annotation

GitHub Actions / test (8.1, 6.*)

Parameter #1 $name of class Codex\Core\App constructor expects string, mixed given.

Check failure on line 250 in app/Plugin.php

View workflow job for this annotation

GitHub Actions / test (8.2, 5.*)

Parameter #1 $name of class Codex\Core\App constructor expects string, mixed given.

Check failure on line 250 in app/Plugin.php

View workflow job for this annotation

GitHub Actions / test (8.2, 6.*)

Parameter #1 $name of class Codex\Core\App constructor expects string, mixed given.

Check failure on line 250 in app/Plugin.php

View workflow job for this annotation

GitHub Actions / test (8.3, 5.*)

Parameter #1 $name of class Codex\Core\App constructor expects string, mixed given.

Check failure on line 250 in app/Plugin.php

View workflow job for this annotation

GitHub Actions / test (8.3, 6.*)

Parameter #1 $name of class Codex\Core\App constructor expects string, mixed given.

Check failure on line 250 in app/Plugin.php

View workflow job for this annotation

GitHub Actions / test (8.4, 5.*)

Parameter #1 $name of class Codex\Core\App constructor expects string, mixed given.

Check failure on line 250 in app/Plugin.php

View workflow job for this annotation

GitHub Actions / test (8.4, 6.*)

Parameter #1 $name of class Codex\Core\App constructor expects string, mixed given.
};
}
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
"require": {
"php": ">=7.4",
"adbario/php-dot-notation": "^3.3",
"pimple/pimple": "^3.5",
"syntatis/utils": "^2.0"
"pimple/pimple": "^3.5"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
Expand Down

0 comments on commit 0a4311f

Please sign in to comment.