Skip to content

Commit

Permalink
clean the codes
Browse files Browse the repository at this point in the history
  • Loading branch information
ArrayIterator committed Oct 14, 2023
1 parent 4247208 commit 9a95763
Show file tree
Hide file tree
Showing 75 changed files with 595 additions and 371 deletions.
4 changes: 3 additions & 1 deletion config.example.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
// site profiling (benchmarking)
// profiling is consume high memory footprints (set false in production)
'profiling' => false,
// print comment after html tag about consume time
'showPerformance' => true,
// enable debug bar (profiling must be enabled)
'debugBar' => false,
// debug bar dark style
Expand All @@ -36,7 +38,7 @@
// 'language' => __DIR__ . '/app/Languages', // language directory
// 'middleware' => __DIR__ . '/app/Middlewares', // middlewares directory
// 'migration' => __DIR__ . '/app/Migrations', // migrations directory
// 'module' => __DIR__ . '/app/Modules', // modules path (DO NOT CHANGE!) this is contain cores
// 'module' => __DIR__ . '/app/Modules', // modules path (DO NOT CHANGE!) this is contained cores
// 'view' => __DIR__ . '/app/Views', // views path
// 'databaseEvent' => __DIR__ . '/app/DatabaseEvents', // database events app
// 'storage' => __DIR__ . '/storage', // temporary storage directory
Expand Down
1 change: 1 addition & 0 deletions src/Assets/Abstracts/AbstractInlineDependency.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static function create(
array $attributes = [],
string ...$inherits
): static {
/** @noinspection DuplicatedCode */
$object = new static($dependencies);
$object->id = $id;
foreach ($attributes as $key => $value) {
Expand Down
1 change: 1 addition & 0 deletions src/Assets/Abstracts/AbstractUriDependency.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static function create(
array $attributes = [],
string ...$inherits
): static {
/** @noinspection DuplicatedCode */
$object = new static($dependencies);
$object->id = $id;
foreach ($attributes as $key => $value) {
Expand Down
3 changes: 2 additions & 1 deletion src/Auth/Generator/HashIdentity.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use function substr;
use function time;
use function trim;
use const PREG_UNMATCHED_AS_NULL;

class HashIdentity
{
Expand Down Expand Up @@ -148,7 +149,7 @@ public function extract(string $generatedHash): ?array
$~x',
$generatedHash,
$match,
\PREG_UNMATCHED_AS_NULL
PREG_UNMATCHED_AS_NULL
);

if ($match === null) {
Expand Down
1 change: 1 addition & 0 deletions src/Auth/Generator/Nonce.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function generate(string $action): string
*/
public function validate(string $nonce, string $action): bool|int
{
/** @noinspection DuplicatedCode */
$valid = $this->cachedResult[$nonce][$action]??null;
if ($valid === self::NONCE_VALID
|| $valid === self::NONCE_INVALID
Expand Down
1 change: 1 addition & 0 deletions src/Auth/Generator/RequestNonce.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function validate(
?ServerRequestInterface $request = null
): bool|int {
$cacheKey = $this->createRequestHash($action, $request);
/** @noinspection DuplicatedCode */
$valid = $this->cachedResult[$nonce][$cacheKey]??null;
if ($valid === self::NONCE_VALID
|| $valid === self::NONCE_INVALID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use function sprintf;
use function substr;
use function trim;
use function var_dump;

abstract class AbstractBasedCoreInjector extends AbstractManagerProfilingListener
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use ArrayAccess\TrayDigita\Benchmark\Injector\ManagerProfiler;
use ArrayAccess\TrayDigita\Event\Interfaces\ManagerInterface;
use SensitiveParameter;
use function var_dump;

class ManagerProfilerInjector extends AbstractBasedCoreInjector
{
Expand Down
18 changes: 11 additions & 7 deletions src/Benchmark/Profiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use ArrayAccess\TrayDigita\Benchmark\Traits\DurationTimeTrait;
use ArrayAccess\TrayDigita\Benchmark\Traits\MemoryTrait;
use ReflectionClass;
use ReflectionException;
use SplObjectStorage;
use Traversable;
use function is_string;
Expand Down Expand Up @@ -175,13 +176,16 @@ public function group(string $id) : GroupInterface
{
if (!isset($this->groups[$id])) {
$this->groupReflection ??= new ReflectionClass(Group::class);
$this->groups[$id] = (function ($obj) use ($id) {
/**
* @var Group $this
*/
$this->{'__construct'}($obj, $id);
return $this;
})->call($this->groupReflection->newInstanceWithoutConstructor(), $this);
try {
$this->groups[$id] = (function ($obj) use ($id) {
/**
* @var Group $this
*/
$this->{'__construct'}($obj, $id);
return $this;
})->call($this->groupReflection->newInstanceWithoutConstructor(), $this);
} catch (ReflectionException) {
}
}

return $this->groups[$id];
Expand Down
29 changes: 18 additions & 11 deletions src/Cache/Cache.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php
/** @noinspection PhpComposerExtensionStubsInspection */
/**
* @noinspection PhpUndefinedClassInspection
* @noinspection PhpComposerExtensionStubsInspection
*/
declare(strict_types=1);

namespace ArrayAccess\TrayDigita\Cache;
Expand Down Expand Up @@ -251,17 +254,21 @@ protected function configureAdapter()
}

$adapter = isset($adapterArgs[$adapter]) ? $adapter : FilesystemAdapter::class;
$ref = new ReflectionClass($adapter);
if ($ref->hasMethod('isSupported')) {
if ($ref->getMethod('isSupported')->isPublic()
&& $ref->getMethod('isSupported')->isStatic()
) {
$adapter = call_user_func([$adapter, 'isSupported'])
? $adapter
: FilesystemAdapter::class;
} else {
$adapter = FilesystemAdapter::class;
try {
$ref = new ReflectionClass($adapter);
if ($ref->hasMethod('isSupported')) {
if ($ref->getMethod('isSupported')->isPublic()
&& $ref->getMethod('isSupported')->isStatic()
) {
$adapter = call_user_func([$adapter, 'isSupported'])
? $adapter
: FilesystemAdapter::class;
} else {
$adapter = FilesystemAdapter::class;
}
}
} catch (Throwable) {
$adapter = FilesystemAdapter::class;
}

switch ($adapter) {
Expand Down
11 changes: 7 additions & 4 deletions src/Collection/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use ArrayAccess\TrayDigita\Util\Filter\IterableHelper;
use IteratorAggregate;
use Traversable;
use function array_key_exists;
use function array_keys;
use function in_array;

class Collection implements CollectionInterface, IteratorAggregate
{
Expand All @@ -22,7 +25,7 @@ public function __construct(iterable $param = [])

public function get($id, $default = null)
{
return \array_key_exists($id, $this->data)
return array_key_exists($id, $this->data)
? $this->data[$id]
: $default;
}
Expand All @@ -39,12 +42,12 @@ public function remove($id)

public function has($id): bool
{
return \array_key_exists($id, $this->data);
return array_key_exists($id, $this->data);
}

public function contain($param): bool
{
return \in_array($this->data, $param, true);
return in_array($this->data, $param, true);
}

public function all(): array
Expand All @@ -54,7 +57,7 @@ public function all(): array

public function keys(): array
{
return \array_keys($this->data);
return array_keys($this->data);
}

public function offsetExists(mixed $offset): bool
Expand Down
1 change: 1 addition & 0 deletions src/ComposerCreateProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ComposerCreateProject
* @noinspection PhpMissingReturnTypeInspection
* @noinspection HtmlRequiredLangAttribute
* @noinspection PhpUnused
* @throws Exception
*/
public static function composerDoCreateProject($event)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
use function trim;
use const DEBUG_BACKTRACE_IGNORE_ARGS;
use const DIRECTORY_SEPARATOR;
use const TD_APP_DIRECTORY;

class Application extends SymfonyConsole implements
ContainerIndicateInterface,
Expand Down Expand Up @@ -100,6 +101,7 @@ class Application extends SymfonyConsole implements
DumpCompletionCommand::class => true
];

/** @noinspection PhpMissingFieldTypeInspection */
private $migrationConfig = null;

public function __construct(
Expand Down Expand Up @@ -162,7 +164,7 @@ private function configureDBCommands(): void
if ($config instanceof Config) {
$migrationPath = $config->get('migration')??null;
} else {
$migrationPath = \TD_APP_DIRECTORY . DIRECTORY_SEPARATOR . 'Migrations';
$migrationPath = TD_APP_DIRECTORY . DIRECTORY_SEPARATOR . 'Migrations';
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/Console/Command/ApplicationChecker/CacheChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use ArrayAccess\TrayDigita\Cache\Cache;
use ArrayAccess\TrayDigita\Collection\Config;
use ArrayAccess\TrayDigita\Console\Command\Traits\WriterHelperTrait;
use ArrayAccess\TrayDigita\Util\Filter\ContainerHelper;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -112,7 +113,8 @@ public function check(InputInterface $input, OutputInterface $output) : int
),
OutputInterface::VERBOSITY_VERBOSE
);
$config = $container->get(Config::class)->get('cache');
$config = ContainerHelper::use(Config::class, $container)
?->get('cache');
if (!$config instanceof Config) {
return Command::SUCCESS;
}
Expand Down
28 changes: 11 additions & 17 deletions src/Console/Command/ApplicationChecker/ConfigChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
use function realpath;
use function sprintf;
use function ucfirst;
use const CONFIG_FILE;
use const DIRECTORY_SEPARATOR;
use const TD_APP_DIRECTORY;

class ConfigChecker extends AbstractChecker
{
Expand Down Expand Up @@ -52,7 +54,7 @@ public function check(InputInterface $input, OutputInterface $output): int
protected function validateEnvironment(InputInterface $input, OutputInterface $output) : int
{
$container = $this->applicationCheck->getContainer();
$config = $container?->get(Config::class)->get('environment');
$config = ContainerHelper::use(Config::class, $container)?->get('environment');
if (!$config instanceof Config) {
$this->writeDanger(
$output,
Expand Down Expand Up @@ -139,16 +141,13 @@ protected function validateEnvironment(InputInterface $input, OutputInterface $o
protected function validatePath(InputInterface $input, OutputInterface $output) : int
{
$container = $this->applicationCheck->getContainer();
$config = $container->has(Config::class)
? $container->get(Config::class)
: null;
$config = $config instanceof Config ? $config : new Config();
$config = ContainerHelper::use(Config::class, $container)??new Config();
$path = $config->get('path');
$path = $path instanceof Config ? $path : null;
$directory = defined('TD_APP_DIRECTORY')
&& is_string(\TD_APP_DIRECTORY)
&& is_dir(\TD_APP_DIRECTORY)
? \TD_APP_DIRECTORY
&& is_string(TD_APP_DIRECTORY)
&& is_dir(TD_APP_DIRECTORY)
? TD_APP_DIRECTORY
: null;
$root = ContainerHelper::use(KernelInterface::class)
->getRootDirectory();
Expand Down Expand Up @@ -233,15 +232,12 @@ protected function validatePath(InputInterface $input, OutputInterface $output)
protected function validateConfig(InputInterface $input, OutputInterface $output) : int
{
$container = $this->applicationCheck->getContainer();
$kernel = $container->has('kernel') ? $container->get('kernel') : null;
$kernel = $kernel instanceof KernelInterface
? $kernel
: Decorator::kernel();
$kernel = ContainerHelper::use(KernelInterface::class, $container)??Decorator::kernel();
if (!$container && ($container = $kernel->getContainer())) {
$this->applicationCheck->setContainer($container);
}
$configFile = $kernel->getConfigFile()?:(
!defined('CONFIG_FILE') ? \CONFIG_FILE : null
!defined('CONFIG_FILE') ? CONFIG_FILE : null
);
if (!is_string($configFile)
|| !file_exists($configFile)
Expand Down Expand Up @@ -282,10 +278,8 @@ protected function validateConfig(InputInterface $input, OutputInterface $output
);
return Command::FAILURE;
}
$config = $container->get(Config::class);
$config = $config instanceof Config
? $config
: null;

$config = ContainerHelper::getNull(Config::class, $container);
if (!$config) {
$this->writeDanger(
$output,
Expand Down
8 changes: 7 additions & 1 deletion src/Console/Command/ApplicationChecker/DatabaseChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

use ArrayAccess\TrayDigita\Console\Command\Traits\WriterHelperTrait;
use ArrayAccess\TrayDigita\Database\Connection;
use ArrayAccess\TrayDigita\Util\Filter\ContainerHelper;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Exception\DriverException;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Exception\MissingMappingDriverImplementation;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -21,6 +23,9 @@ class DatabaseChecker extends AbstractChecker

protected ?EntityManager $entityManager = null;

/**
* @throws MissingMappingDriverImplementation
*/
public function check(InputInterface $input, OutputInterface $output) : int
{
$container = $this->applicationCheck->getContainer();
Expand All @@ -33,7 +38,7 @@ public function check(InputInterface $input, OutputInterface $output) : int
return Command::FAILURE;
}

$database = $container->get(Connection::class);
$database = ContainerHelper::getNull(Connection::class, $container);
if (!$database instanceof Connection) {
$this->write(
$output,
Expand Down Expand Up @@ -85,6 +90,7 @@ public function check(InputInterface $input, OutputInterface $output) : int
);
}

/** @noinspection DuplicatedCode */
if (!$error && !$this->entityManager) {
$orm = clone $ormConfig;
$cache = new ArrayAdapter();
Expand Down
7 changes: 6 additions & 1 deletion src/Console/Command/ApplicationChecker/TranslatorChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Throwable;
use function sprintf;

class TranslatorChecker extends AbstractChecker
Expand All @@ -24,7 +25,11 @@ public function check(InputInterface $input, OutputInterface $output): int
);
return Command::FAILURE;
}
$translator = $container->get(TranslatorInterface::class);
try {
$translator = $container->get(TranslatorInterface::class);
} catch (Throwable) {
$translator = null;
}
if (!$translator instanceof TranslatorInterface) {
$this->writeDanger(
$output,
Expand Down
Loading

0 comments on commit 9a95763

Please sign in to comment.