Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code quality improvements #1284

Merged
merged 10 commits into from
Mar 14, 2023
2 changes: 1 addition & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This serves two purposes:
- for new features.

### Changed
- for changes in existing functionality.
- General compatible code quality improvements https://github.com/hydephp/develop/pull/1284

### Deprecated
- for soon-to-be removed features.
Expand Down
8 changes: 5 additions & 3 deletions packages/framework/src/Console/Commands/RouteListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Hyde\Console\Concerns\Command;
use Hyde\Hyde;
use Hyde\Pages\InMemoryPage;
use Hyde\Support\Models\Route;
use Hyde\Support\Models\RouteList;
use Hyde\Support\Models\RouteListItem;
Expand Down Expand Up @@ -47,9 +48,10 @@ protected function stylePageType(string $class): string
{
$type = parent::stylePageType($class);

/** @experimental */
if ($type === 'InMemoryPage' && $this->route->getPage()->hasMacro('typeLabel')) {
$type .= sprintf(' <fg=gray>(%s)</>', $this->route->getPage()->typeLabel());
$page = $this->route->getPage();
/** @experimental The typeLabel macro is experimental */
if ($page instanceof InMemoryPage && $page->hasMacro('typeLabel')) {
$type .= sprintf(' <fg=gray>(%s)</>', $page->__call('typeLabel', []));
}

return $type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function add(MetadataElementContract|string $element): static

protected function addElement(string $type, MetadataElementContract $element): static
{
$this->$type[$element->uniqueKey()] = $element;
$this->{$type}[$element->uniqueKey()] = $element;

return $this;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/framework/src/Framework/Services/MarkdownService.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public static function normalizeIndentationLevel(string $string): string

foreach ($lines as $lineNumber => $line) {
if ($lineNumber >= $startNumber) {
$lines[$lineNumber] = substr($line, $indentationLevel);
$lines[$lineNumber] = substr((string) $line, $indentationLevel);
}
}

Expand All @@ -247,9 +247,9 @@ protected static function getNormalizedLines(string $string): array
protected static function findLineContentPositions(array $lines): array
{
foreach ($lines as $lineNumber => $line) {
if (filled(trim($line))) {
$lineLen = strlen($line);
$stripLen = strlen(ltrim($line)); // Length of the line without indentation lets us know its indentation level, and thus how much to strip from each line
if (filled(trim((string) $line))) {
$lineLen = strlen((string) $line);
$stripLen = strlen(ltrim((string) $line)); // Length of the line without indentation lets us know its indentation level, and thus how much to strip from each line

if ($lineLen !== $stripLen) {
return [$lineNumber, $lineLen - $stripLen];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static function postprocess(string $html): string
protected static function lineMatchesPattern(string $line): bool
{
foreach (static::$patterns as $pattern) {
if (str_starts_with(strtolower($line), $pattern)) {
if (str_starts_with(strtolower($line), (string) $pattern)) {
return true;
}
}
Expand Down