Skip to content

Commit

Permalink
Add missing phpdoc and coding style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
giuscris committed Dec 8, 2024
1 parent 14feb2a commit 1b64a7d
Show file tree
Hide file tree
Showing 169 changed files with 1,756 additions and 472 deletions.
2 changes: 1 addition & 1 deletion formwork/.php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@
'single_line_empty_body' => false,
'single_quote' => true,
'string_implicit_backslashes' => true,
'trailing_comma_in_multiline' => true,
'trailing_comma_in_multiline' => ['after_heredoc' => true, 'elements' => ['array_destructuring', 'arrays', 'match', 'parameters']],
])
->setFinder($finder);
2 changes: 1 addition & 1 deletion formwork/fields/date.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
$format = match (strtolower($type)) {
'pattern' => Date::patternToFormat($format),
'date' => $format,
default => throw new InvalidArgumentException('Invalid date format type')
default => throw new InvalidArgumentException('Invalid date format type'),
};
}
return $field->isEmpty() ? '' : Date::formatTimestamp($field->toTimestamp(), $format, $translation);
Expand Down
3 changes: 0 additions & 3 deletions formwork/src/Assets/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ class Assets
*/
protected string $baseUri;

/**
* Create a new Assets instance
*/
public function __construct(string $basePath, string $baseUri)
{
$this->basePath = FileSystem::normalizePath($basePath);
Expand Down
4 changes: 1 addition & 3 deletions formwork/src/Backup/Backupper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ class Backupper
protected const string DATE_FORMAT = 'YmdHis';

/**
* Return a new Backupper instance
*
* @param array<mixed> $options
*/
public function __construct(
protected array $options
protected array $options,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion formwork/src/Cache/AbstractCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
abstract class AbstractCache
{
/**
* Return cached resource
* Fetch cached resource
*/
abstract public function fetch(string $key): mixed;

Expand Down
2 changes: 1 addition & 1 deletion formwork/src/Cache/CacheItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class CacheItem implements CacheItemInterface
public function __construct(
protected mixed $value,
protected int $expirationTime,
protected int $cachedTime
protected int $cachedTime,
) {
}

Expand Down
24 changes: 4 additions & 20 deletions formwork/src/Cache/FilesCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ class FilesCache extends AbstractCache
* @param string $path Cache path
* @param int $defaultTtl Cached data time-to-live
*/
public function __construct(protected string $path, protected int $defaultTtl)
{
public function __construct(
protected string $path,
protected int $defaultTtl,
) {
if (!FileSystem::exists($this->path)) {
FileSystem::createDirectory($this->path, recursive: true);
}
}

/**
* @inheritdoc
*/
public function fetch(string $key): mixed
{
if ($this->has($key)) {
Expand All @@ -33,45 +32,30 @@ public function fetch(string $key): mixed
return null;
}

/**
* @inheritdoc
*/
public function save(string $key, mixed $value, ?int $ttl = null): void
{
$cacheItem = new CacheItem($value, time() + ($ttl ?? $this->defaultTtl), time());
Php::encodeToFile($cacheItem, $this->getFile($key));
}

/**
* @inheritdoc
*/
public function delete(string $key): void
{
if ($this->has($key)) {
FileSystem::delete($this->getFile($key));
}
}

/**
* @inheritdoc
*/
public function clear(): void
{
FileSystem::delete($this->path, recursive: true);
FileSystem::createDirectory($this->path, recursive: true);
}

/**
* @inheritdoc
*/
public function has(string $key): bool
{
return FileSystem::exists($this->getFile($key)) && !$this->hasExpired($key);
}

/**
* @inheritdoc
*/
public function cachedTime(string $key): ?int
{
return $this->has($key) ? FileSystem::lastModifiedTime($this->getFile($key)) : null;
Expand Down
33 changes: 30 additions & 3 deletions formwork/src/Cms/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ final class App
*/
public const string VERSION = '2.0.0-beta.2';

protected Container $container;

/**
* Create a new Formwork instance
* App services container
*/
protected Container $container;

public function __construct()
{
$this->initializeSingleton();
Expand All @@ -75,36 +75,57 @@ public function __call(string $name, array $arguments): mixed
throw new BadMethodCallException(sprintf('Call to undefined method %s::%s()', self::class, $name));
}

/**
* Get Config instance
*/
public function config(): Config
{
return $this->container->get(Config::class);
}

/**
* Get Router instance
*/
public function router(): Router
{
return $this->container->get(Router::class);
}

/**
* Get Site instance
*/
public function site(): Site
{
return $this->container->get(Site::class);
}

/**
* Get Request instance
*/
public function request(): Request
{
return $this->container->get(Request::class);
}

/**
* Get Schemes instance
*/
public function schemes(): Schemes
{
return $this->container->get(Schemes::class);
}

/**
* Get Translations instance
*/
public function translations(): Translations
{
return $this->container->get(Translations::class);
}

/**
* Get Panel instance
*/
public function panel(): Panel
{
return $this->container->get(Panel::class);
Expand Down Expand Up @@ -155,6 +176,9 @@ public function run(): Response
return $response;
}

/**
* Define app services
*/
protected function loadServices(Container $container): void
{
$container->define(Container::class, $container);
Expand Down Expand Up @@ -258,6 +282,9 @@ protected function loadRoutes(): void
$this->router()->loadFromFile($this->config()->get('system.routes.files.system'));
}

/**
* Load error handler
*/
protected function loadErrorHandler(): void
{
ini_set('display_errors', 0);
Expand Down
17 changes: 15 additions & 2 deletions formwork/src/Cms/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class Site extends Model implements Stringable
*/
protected ?string $path = null;

/**
* Site content path
*/
protected ?string $contentPath = null;

/**
Expand Down Expand Up @@ -97,8 +100,6 @@ class Site extends Model implements Stringable
protected array $routeAliases;

/**
* Create a new Site instance
*
* @param array<string, mixed> $data
*/
public function __construct(
Expand Down Expand Up @@ -424,11 +425,17 @@ public function isDeletable(): bool
return false;
}

/**
* Return defined schemes
*/
public function schemes(): Schemes
{
return $this->app->schemes();
}

/**
* Load site dependencies
*/
public function load(): void
{
$this->scheme = $this->app->schemes()->get('config.site');
Expand Down Expand Up @@ -463,11 +470,17 @@ protected function storage(): array
return $this->storage;
}

/**
* Set site path
*/
protected function setPath(string $path): void
{
$this->path = $this->data['path'] = FileSystem::normalizePath($path . '/');
}

/**
* Set site content path
*/
protected function setContentPath(string $path): void
{
$this->contentPath = FileSystem::normalizePath($path . '/');
Expand Down
30 changes: 28 additions & 2 deletions formwork/src/Commands/ServeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,37 @@
class ServeCommand
{
/**
* Current request data for the server process
*
* @var array<mixed>
*/
protected array $requestData;

/**
* PHP process
*/
protected Process $process;

/**
* CLImate instance
*/
protected CLImate $climate;

/**
* Server start time
*/
protected float $startTime;

public function __construct(protected string $host = '127.0.0.1', protected int $port = 8000)
{
public function __construct(
protected string $host = '127.0.0.1',
protected int $port = 8000,
) {
$this->climate = new CLImate();
}

/**
* Start the server
*/
public function start(): void
{
$this->startTime = microtime(true);
Expand All @@ -47,6 +63,8 @@ public function start(): void
}

/**
* Handle server output
*
* @param list<string> $lines
*/
protected function handleOutput(array $lines): void
Expand Down Expand Up @@ -136,6 +154,8 @@ protected function handleOutput(array $lines): void
}

/**
* Split request message into parts
*
* @return list<?string>
*/
protected function splitMessage(string $message): array
Expand All @@ -145,6 +165,9 @@ protected function splitMessage(string $message): array
return $matches;
}

/**
* Colorize status code
*/
protected function colorStatus(int $status): string
{
if ($status <= 299) {
Expand All @@ -163,6 +186,9 @@ protected function colorStatus(int $status): string
throw new UnexpectedValueException(sprintf('Unexpected status code %d', $status));
}

/**
* Format time interval
*/
protected function formatTime(float $dt): string
{
if ($dt > 60) {
Expand Down
Loading

0 comments on commit 1b64a7d

Please sign in to comment.