Skip to content

Commit

Permalink
Cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
freost committed Nov 11, 2024
1 parent 37f6da2 commit c25490b
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 98 deletions.
15 changes: 11 additions & 4 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
'blank_line_after_namespace' => true,
'blank_line_after_opening_tag' => true,
'cast_spaces' => true,
'class_reference_name_casing' => true,
'combine_nested_dirname' => true,
'concat_space' => ['spacing' => 'one'],
'constant_case' => true,
'dir_constant' => true,
'curly_braces_position' => true,
'dir_constant' => true,
'elseif' => true,
'encoding' => true,
'full_opening_tag' => true,
Expand All @@ -24,6 +25,8 @@
'function_typehint_space' => true,
'get_class_to_class_keyword' => true,
'heredoc_to_nowdoc' => true,
'integer_literal_case' => true,
'lambda_not_used_import' => true,
'linebreak_after_opening_tag' => true,
'list_syntax' => ['syntax' => 'short'],
'logical_operators' => true,
Expand All @@ -34,7 +37,7 @@
'magic_method_casing' => true,
'method_argument_space' => ['on_multiline' => 'ignore'],
'native_function_casing' => true,
'native_function_type_declaration_casing' => true,
'native_type_declaration_casing' => true,
'no_alias_functions' => true,
'no_blank_lines_after_phpdoc' => true,
'no_closing_tag' => true,
Expand All @@ -44,8 +47,7 @@
'no_leading_namespace_whitespace' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_spaces_inside_parenthesis' => true,
'no_trailing_comma_in_list_call' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_trailing_comma_in_singleline' => true,
'no_trailing_whitespace_in_comment' => true,
'no_trailing_whitespace' => true,
'no_unset_cast' => true,
Expand All @@ -57,7 +59,9 @@
'normalize_index_brace' => true,
'nullable_type_declaration_for_default_null_value' => true,
'object_operator_without_whitespace' => true,
'octal_notation' => true,
'ordered_imports' => ['imports_order' => ['class', 'function', 'const']],
'ordered_interfaces' => true,
'ordered_traits' => true,
'ordered_types' => true,
'phpdoc_align' => true,
Expand All @@ -76,15 +80,18 @@
'phpdoc_types' => true,
'pow_to_exponentiation' => true,
'return_type_declaration' => true,
'self_static_accessor' => true,
'short_scalar_cast' => true,
'simple_to_complex_string_variable' => true,
'single_blank_line_at_eof' => true,
'single_blank_line_before_namespace' => true,
'single_class_element_per_statement' => true,
'single_import_per_statement' => true,
'single_line_after_imports' => true,
'single_line_comment_style' => ['comment_types' => ['hash']],
'single_quote' => true,
'single_space_around_construct' => true,
'single_trait_insert_per_statement' => true,
'space_after_semicolon' => true,
'standardize_not_equals' => true,
'switch_case_semicolon_to_colon' => true,
Expand Down
4 changes: 1 addition & 3 deletions src/mako/application/services/CacheService.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ public function register(): void

// Register the default cache store

$this->container->registerSingleton(StoreInterface::class, static function ($container) {
return $container->get(CacheManager::class)->getInstance();
});
$this->container->registerSingleton(StoreInterface::class, static fn ($container) => $container->get(CacheManager::class)->getInstance());
}
}
4 changes: 1 addition & 3 deletions src/mako/application/services/ViewFactoryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ public function register(): void

// Register template renderer

$factory->extend('.tpl.php', function () use ($fileSystem) {
return new Template($fileSystem, $this->getStoragePath());
});
$factory->extend('.tpl.php', fn () => new Template($fileSystem, $this->getStoragePath()));

// Return factory instance

Expand Down
12 changes: 6 additions & 6 deletions src/mako/chrono/traits/TimeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ public static function createFromTimestamp(float|int $timestamp, null|DateTimeZo
*/
public static function createFromDOSTimestamp(int $timestamp, null|DateTimeZone|string $timeZone = null): static
{
$year = (($timestamp >> 25) & 0x7f) + 1980;
$mon = ($timestamp >> 21) & 0x0f;
$mday = ($timestamp >> 16) & 0x1f;
$hours = ($timestamp >> 11) & 0x1f;
$minutes = ($timestamp >> 5) & 0x3f;
$seconds = 2 * ($timestamp & 0x1f);
$year = (($timestamp >> 25) & 0x7F) + 1980;
$mon = ($timestamp >> 21) & 0x0F;
$mday = ($timestamp >> 16) & 0x1F;
$hours = ($timestamp >> 11) & 0x1F;
$minutes = ($timestamp >> 5) & 0x3F;
$seconds = 2 * ($timestamp & 0x1F);

$timestamp = mktime($hours, $minutes, $seconds, $mon, $mday, $year);

Expand Down
2 changes: 1 addition & 1 deletion src/mako/cli/output/writer/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function setStream($stream): void
public function isDirect(): bool
{
if ($this->isDirect === null) {
$this->isDirect = (0020000 === (fstat($this->stream)['mode'] & 0170000));
$this->isDirect = (0o020000 === (fstat($this->stream)['mode'] & 0o170000));
}

return $this->isDirect;
Expand Down
8 changes: 2 additions & 6 deletions src/mako/database/midgard/traits/NullableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,10 @@ protected function getNullableTraitHooks(): array
{
return [
'beforeInsert' => [
function ($values, $query): array {
return $this->setEmptyNullablesToNull($values);
},
fn ($values, $query): array => $this->setEmptyNullablesToNull($values),
],
'beforeUpdate' => [
function ($values, $query): array {
return $this->setEmptyNullablesToNull($values);
},
fn ($values, $query): array => $this->setEmptyNullablesToNull($values),
],
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/mako/file/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static function hasPermissions(int $permissions, Permission ...$permissio
throw new InvalidArgumentException(vsprintf('The integer [ %s ] does not represent a valid octal between 0o000 and 0o777.', [$permissions]));
}

$permission = empty($permission) ? 0o000 : static::calculate(...$permission);
$permission = empty($permission) ? 0o000 : self::calculate(...$permission);

if ($permission === 0o000) {
return $permissions === 0o000;
Expand Down
130 changes: 65 additions & 65 deletions src/mako/http/response/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,83 +108,83 @@ public function getMessage(): string
return match ($this) {
// 1xx Informational

static::CONTINUE => 'Continue',
static::SWITCHING_PROTOCOLS => 'Switching Protocols',
static::PROCESSING => 'Processing',
static::EARLY_HINTS => 'Early Hints',
self::CONTINUE => 'Continue',
self::SWITCHING_PROTOCOLS => 'Switching Protocols',
self::PROCESSING => 'Processing',
self::EARLY_HINTS => 'Early Hints',

// 2xx Success

static::OK => 'OK',
static::CREATED => 'Created',
static::ACCEPTED => 'Accepted',
static::NON_AUTHORITATIVE_INFORMATION => 'Non-Authoritative Information',
static::NO_CONTENT => 'No Content',
static::RESET_CONTENT => 'Reset Content',
static::PARTIAL_CONTENT => 'Partial Content',
static::MULTI_STATUS => 'Multi-Status',
static::ALREADY_REPORTED => 'Already Reported',
static::IM_USED => 'IM Used',
self::OK => 'OK',
self::CREATED => 'Created',
self::ACCEPTED => 'Accepted',
self::NON_AUTHORITATIVE_INFORMATION => 'Non-Authoritative Information',
self::NO_CONTENT => 'No Content',
self::RESET_CONTENT => 'Reset Content',
self::PARTIAL_CONTENT => 'Partial Content',
self::MULTI_STATUS => 'Multi-Status',
self::ALREADY_REPORTED => 'Already Reported',
self::IM_USED => 'IM Used',

// 3xx Redirection

static::MULTIPLE_CHOICES => 'Multiple Choices',
static::MOVED_PERMANENTLY => 'Moved Permanently',
static::FOUND => 'Found',
static::SEE_OTHER => 'See Other',
static::NOT_MODIFIED => 'Not Modified',
static::USE_PROXY => 'Use Proxy',
static::TEMPORARY_REDIRECT => 'Temporary Redirect',
static::PERMANENT_REDIRECT => 'Permanent Redirect',
self::MULTIPLE_CHOICES => 'Multiple Choices',
self::MOVED_PERMANENTLY => 'Moved Permanently',
self::FOUND => 'Found',
self::SEE_OTHER => 'See Other',
self::NOT_MODIFIED => 'Not Modified',
self::USE_PROXY => 'Use Proxy',
self::TEMPORARY_REDIRECT => 'Temporary Redirect',
self::PERMANENT_REDIRECT => 'Permanent Redirect',

// 4xx Client Error

static::BAD_REQUEST => 'Bad Request',
static::UNAUTHORIZED => 'Unauthorized',
static::PAYMENT_REQUIRED => 'Payment Required',
static::FORBIDDEN => 'Forbidden',
static::NOT_FOUND => 'Not Found',
static::METHOD_NOT_ALLOWED => 'Method Not Allowed',
static::NOT_ACCEPTABLE => 'Not Acceptable',
static::PROXY_AUTHENTICATION_REQUIRED => 'Proxy Authentication Required',
static::REQUEST_TIMEOUT => 'Request Timeout',
static::CONFLICT => 'Conflict',
static::GONE => 'Gone',
static::LENGTH_REQUIRED => 'Length Required',
static::PRECONDITION_FAILED => 'Precondition Failed',
static::PAYLOAD_TOO_LARGE => 'Payload Too Large',
static::URI_TOO_LONG => 'URI Too Long',
static::UNSUPPORTED_MEDIA_TYPE => 'Unsupported Media Type',
static::RANGE_NOT_SATISFIABLE => 'Range Not Satisfiable',
static::EXPECTATION_FAILED => 'Expectation Failed',
static::IM_A_TEAPOT => 'I\'m a teapot',
static::AUTENTICATION_TIMEOUT => 'Authentication Timeout',
static::MISDIRECTED_REQUEST => 'Misdirected Request',
static::UNPROCESSABLE_ENTITY => 'Unprocessable Entity',
static::LOCKED => 'Locked',
static::FAILED_DEPENDENCY => 'Failed Dependency',
static::TOO_EARLY => 'Too Early',
static::UPGRADE_REQUIRED => 'Upgrade Required',
static::PRECONDITION_REQUIRED => 'Precondition Required',
static::TOO_MANY_REQUESTS => 'Too Many Requests',
static::REQUEST_HEADER_FIELDS_TOO_LARGE => 'Request Header Fields Too Large',
static::UNAVAILABLE_FOR_LEGAL_REASONS => 'Unavailable For Legal Reasons',
static::INVALID_TOKEN => 'Invalid Token',
static::TOKEN_REQUIRED => 'Token Required',
self::BAD_REQUEST => 'Bad Request',
self::UNAUTHORIZED => 'Unauthorized',
self::PAYMENT_REQUIRED => 'Payment Required',
self::FORBIDDEN => 'Forbidden',
self::NOT_FOUND => 'Not Found',
self::METHOD_NOT_ALLOWED => 'Method Not Allowed',
self::NOT_ACCEPTABLE => 'Not Acceptable',
self::PROXY_AUTHENTICATION_REQUIRED => 'Proxy Authentication Required',
self::REQUEST_TIMEOUT => 'Request Timeout',
self::CONFLICT => 'Conflict',
self::GONE => 'Gone',
self::LENGTH_REQUIRED => 'Length Required',
self::PRECONDITION_FAILED => 'Precondition Failed',
self::PAYLOAD_TOO_LARGE => 'Payload Too Large',
self::URI_TOO_LONG => 'URI Too Long',
self::UNSUPPORTED_MEDIA_TYPE => 'Unsupported Media Type',
self::RANGE_NOT_SATISFIABLE => 'Range Not Satisfiable',
self::EXPECTATION_FAILED => 'Expectation Failed',
self::IM_A_TEAPOT => 'I\'m a teapot',
self::AUTENTICATION_TIMEOUT => 'Authentication Timeout',
self::MISDIRECTED_REQUEST => 'Misdirected Request',
self::UNPROCESSABLE_ENTITY => 'Unprocessable Entity',
self::LOCKED => 'Locked',
self::FAILED_DEPENDENCY => 'Failed Dependency',
self::TOO_EARLY => 'Too Early',
self::UPGRADE_REQUIRED => 'Upgrade Required',
self::PRECONDITION_REQUIRED => 'Precondition Required',
self::TOO_MANY_REQUESTS => 'Too Many Requests',
self::REQUEST_HEADER_FIELDS_TOO_LARGE => 'Request Header Fields Too Large',
self::UNAVAILABLE_FOR_LEGAL_REASONS => 'Unavailable For Legal Reasons',
self::INVALID_TOKEN => 'Invalid Token',
self::TOKEN_REQUIRED => 'Token Required',

// 5xx Server Error

static::INTERNAL_SERVER_ERROR => 'Internal Server Error',
static::NOT_IMPLEMENTED => 'Not Implemented',
static::BAD_GATEWAY => 'Bad Gateway',
static::SERVICE_UNAVAILABLE => 'Service Unavailable',
static::GATEWAY_TIMEOUT => 'Gateway Timeout',
static::HTTP_VERSION_NOT_SUPPORTED => 'HTTP Version Not Supported',
static::VARIANT_ALSO_NEGOTIATES => 'Variant Also Negotiates',
static::INSUFFICIENT_STORAGE => 'Insufficient Storage',
static::LOOP_DETECTED => 'Loop Detected',
static::NOT_EXTENDED => 'Not Extended',
static::NETWORK_AUTHENTICATION_REQUIRED => 'Network Authentication Required',
self::INTERNAL_SERVER_ERROR => 'Internal Server Error',
self::NOT_IMPLEMENTED => 'Not Implemented',
self::BAD_GATEWAY => 'Bad Gateway',
self::SERVICE_UNAVAILABLE => 'Service Unavailable',
self::GATEWAY_TIMEOUT => 'Gateway Timeout',
self::HTTP_VERSION_NOT_SUPPORTED => 'HTTP Version Not Supported',
self::VARIANT_ALSO_NEGOTIATES => 'Variant Also Negotiates',
self::INSUFFICIENT_STORAGE => 'Insufficient Storage',
self::LOOP_DETECTED => 'Loop Detected',
self::NOT_EXTENDED => 'Not Extended',
self::NETWORK_AUTHENTICATION_REQUIRED => 'Network Authentication Required',
};
}
}
16 changes: 8 additions & 8 deletions src/mako/utility/UUID.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ public static function v3(string $namespace, string $name): string
'%s-%s-%x-%x-%s',
substr($hash, 0, 8),
substr($hash, 8, 4),
(hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x3000,
(hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
(hexdec(substr($hash, 12, 4)) & 0x0FFF) | 0x3000,
(hexdec(substr($hash, 16, 4)) & 0x3FFF) | 0x8000,
substr($hash, 20, 12)
);
}
Expand All @@ -128,9 +128,9 @@ public static function v4(): string
{
$random = random_bytes(16);

$random[6] = chr(ord($random[6]) & 0x0f | 0x40);
$random[6] = chr(ord($random[6]) & 0x0F | 0x40);

$random[8] = chr(ord($random[8]) & 0x3f | 0x80);
$random[8] = chr(ord($random[8]) & 0x3F | 0x80);

return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($random), 4));
}
Expand All @@ -144,9 +144,9 @@ public static function v4Sequential(): string

$random = hex2bin(dechex((int) ($sec . substr($usec, 2, 5))) . bin2hex(random_bytes(10)));

$random[6] = chr(ord($random[6]) & 0x0f | 0x40);
$random[6] = chr(ord($random[6]) & 0x0F | 0x40);

$random[8] = chr(ord($random[8]) & 0x3f | 0x80);
$random[8] = chr(ord($random[8]) & 0x3F | 0x80);

return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($random), 4));
}
Expand All @@ -162,8 +162,8 @@ public static function v5(string $namespace, string $name): string
'%s-%s-%x-%x-%s',
substr($hash, 0, 8),
substr($hash, 8, 4),
(hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x5000,
(hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
(hexdec(substr($hash, 12, 4)) & 0x0FFF) | 0x5000,
(hexdec(substr($hash, 16, 4)) & 0x3FFF) | 0x8000,
substr($hash, 20, 12)
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/mako/view/renderers/traits/EscaperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected function attributeEscaper(array $matches): string
// The following replaces characters undefined in HTML with the
// hex entity for the Unicode replacement character.

if (($ord <= 0x1f && $chr !== "\t" && $chr !== "\n" && $chr !== "\r") || ($ord >= 0x7f && $ord <= 0x9f)) {
if (($ord <= 0x1F && $chr !== "\t" && $chr !== "\n" && $chr !== "\r") || ($ord >= 0x7F && $ord <= 0x9F)) {
return '&#xFFFD;';
}

Expand Down

0 comments on commit c25490b

Please sign in to comment.