Skip to content

Commit

Permalink
Merge pull request #303 from hydephp/fix-code-issues
Browse files Browse the repository at this point in the history
Fix minor code issues found by static analyses
  • Loading branch information
caendesilva authored Jul 31, 2022
2 parents 7997b24 + ad2a8c6 commit ba6b1e1
Show file tree
Hide file tree
Showing 29 changed files with 138 additions and 43 deletions.
32 changes: 32 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

### About

Keep an Unreleased section at the top to track upcoming changes.

This serves two purposes:

1. People can see what changes they might expect in upcoming releases
2. At release time, you can move the Unreleased section changes into a new release version section.
This release refactors and cleans up a large part of the internal code base. For most end users, this will not have any visible effect. If you have developed integrations that depend on methods you may want to take a closer look at the associated pull requests as it is not practical to list them all here.

### Added
- internal: Adds methods to the HydeKernelContract interface
Expand Down
3 changes: 3 additions & 0 deletions packages/framework/src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Illuminate\Filesystem\Filesystem;
use Illuminate\Foundation\PackageManifest;

/**
* @property mixed $app
*/
class Application extends \LaravelZero\Framework\Application
{
/**
Expand Down
13 changes: 8 additions & 5 deletions packages/framework/src/Commands/HydeBuildStaticSiteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@ public function runPostBuildActions(): void
protected function printFinishMessage(float $time_start): void
{
$execution_time = (microtime(true) - $time_start);
$this->info(sprintf('All done! Finished in %s seconds. (%sms)',
number_format($execution_time, 2), number_format($execution_time * 1000, 2)
$this->info(sprintf(
'All done! Finished in %s seconds. (%sms)',
number_format($execution_time, 2),
number_format($execution_time * 1000, 2)
));

$this->info('Congratulations! 🎉 Your static site has been built!');
Expand All @@ -149,10 +151,11 @@ protected function runNodeCommand(string $command, string $message, ?string $act
{
$this->info($message.' This may take a second.');

$output = shell_exec(sprintf('%s%s',
$output = shell_exec(sprintf(
'%s%s',
app()->environment() === 'testing' ? 'echo ' : '',
$command)
);
$command
));

$this->line($output ?? sprintf(
'<fg=red>Could not %s! Is NPM installed?</>',
Expand Down
5 changes: 3 additions & 2 deletions packages/framework/src/Commands/HydeDebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Hyde\Framework\Commands;

use Composer\InstalledVersions;
use Hyde\Framework\Hyde;
use LaravelZero\Framework\Commands\Command;

Expand Down Expand Up @@ -44,8 +45,8 @@ public function handle(): int

$this->newLine();
$this->comment('Git Version: '.app('git.version'));
$this->comment('Hyde Version: '.(\Composer\InstalledVersions::getPrettyVersion('hyde/hyde') ?: 'unreleased'));
$this->comment('Framework Version: '.(\Composer\InstalledVersions::getPrettyVersion('hyde/framework') ?: 'unreleased'));
$this->comment('Hyde Version: '.(InstalledVersions::getPrettyVersion('hyde/hyde') ?: 'unreleased'));
$this->comment('Framework Version: '.(InstalledVersions::getPrettyVersion('hyde/framework') ?: 'unreleased'));

$this->newLine();
$this->comment('App Env: '.app('env'));
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/src/Commands/HydeValidateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use LaravelZero\Framework\Commands\Command;

/**
* @see \Hyde\Testing\Feature\Commands\HydeValidateCommandTest
* @see \Hyde\Framework\Testing\Feature\Commands\HydeValidateCommandTest
*/
class HydeValidateCommand extends Command
{
Expand Down
1 change: 0 additions & 1 deletion packages/framework/src/Concerns/HasArticleMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Hyde\Framework\Contracts\RouteContract;
use Hyde\Framework\Hyde;
use Hyde\Framework\Models\Pages\MarkdownPost;

/**
* Generates article metadata for a MarkdownPost.
Expand Down
4 changes: 2 additions & 2 deletions packages/framework/src/Concerns/HasAuthor.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public function constructAuthor(): void
{
if (isset($this->matter['author'])) {
if (is_string($this->matter['author'])) {
// If the author is a string, we assume it's a username
// and we'll try to find the author in the config
// If the author is a string, we assume it's a username,
// so we'll try to find the author in the config
$this->author = $this->findAuthor($this->matter['author']);
}
if (is_array($this->matter['author'])) {
Expand Down
3 changes: 2 additions & 1 deletion packages/framework/src/Concerns/HasPageMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ public function hasOpenGraphTitleInConfig(): bool

protected function makeRssFeedLink(): string
{
return sprintf('<link rel="alternate" type="application/rss+xml" title="%s" href="%s" />',
return sprintf(
'<link rel="alternate" type="application/rss+xml" title="%s" href="%s" />',
RssFeedService::getDescription(),
Hyde::url(RssFeedService::getDefaultOutputFilename())
);
Expand Down
5 changes: 0 additions & 5 deletions packages/framework/src/Contracts/AbstractBuildTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
use Illuminate\Console\Concerns\InteractsWithIO;
use Illuminate\Console\OutputStyle;

/**
* @experimental This feature was recently added and may be changed without notice.
*
* @since 0.40.0
*/
abstract class AbstractBuildTask implements BuildTaskContract
{
use InteractsWithIO;
Expand Down
2 changes: 2 additions & 0 deletions packages/framework/src/Exceptions/FileConflictException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ class FileConflictException extends Exception
public function __construct(?string $path = null)
{
$this->message = $path ? "File already exists: $path" : $this->message;

parent::__construct($this->message, $this->code);
}
}
2 changes: 2 additions & 0 deletions packages/framework/src/Exceptions/FileNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ class FileNotFoundException extends Exception
public function __construct(?string $path = null)
{
$this->message = $path ? "File $path not found." : $this->message;

parent::__construct($this->message, $this->code);
}
}
2 changes: 1 addition & 1 deletion packages/framework/src/Models/MarkdownDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Illuminate\Support\Arr;

/**
* @see \Hyde\Framework\Testing\MarkdownDocumentTest
* @see \Hyde\Framework\Testing\Unit\MarkdownDocumentTest
*/
class MarkdownDocument implements MarkdownDocumentContract
{
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/src/Models/NavItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* You have a few options to construct a navigation menu item:
* 1. You can supply a Route directly and explicit properties to the constructor
* 2. You can use NavItem::fromRoute() to use data from the route
* 3. You can use NavItem::leadsTo(URI, Title, ?priority) for an external or unrouted link
* 3. You can use NavItem::leadsTo(URI, Title, ?priority) for an external or un-routed link
*/
class NavItem
{
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/src/Models/NavigationMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct()
$this->items = new Collection();
}

public static function create(?RouteContract $currentRoute = null): static
public static function create(): static
{
return (new static())->generate()->filter()->sort();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/src/Models/Pages/DocumentationPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DocumentationPage extends AbstractMarkdownPage
public ?string $category;

/**
* The path to the page relative to the configured docs directory.
* The path to the page relative to the configured `_docs` directory.
* Generally only needed if the page is in a subdirectory.
*/
public ?string $localPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Illuminate\Support\Str;

/**
* Parses a Markdown file in the configured docs directory into a DocumentationPage object.
* Parses a Markdown file in the configured `_docs` directory into a DocumentationPage object.
*
* If the file is in a subdirectory relative to the base source directory (default _docs),
* the subdirectory name will be used as the page's category. This only works for one level,
Expand Down
4 changes: 2 additions & 2 deletions packages/framework/src/Models/ValidationResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Hyde\Framework\Models;

/**
* @see \Hyde\Testing\Feature\Services\ValidationServiceTest
* @see \Hyde\Testing\Feature\Commands\HydeValidateCommandTest
* @see \Hyde\Framework\Testing\Feature\Services\ValidationServiceTest
* @see \Hyde\Framework\Testing\Feature\Commands\HydeValidateCommandTest
*/
class ValidationResult
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Hyde\Framework\Modules\DataCollections;

use Hyde\Framework\Hyde;
use Hyde\Framework\Models\MarkdownDocument;
use Hyde\Framework\Services\MarkdownFileService;
use Illuminate\Support\Collection;

Expand Down
10 changes: 6 additions & 4 deletions packages/framework/src/Services/BuildService.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public function transferMediaAssets(): void
$collection = DiscoveryService::getMediaAssetFiles();
$this->comment('Transferring Media Assets...');

$this->withProgressBar($collection,
$this->withProgressBar(
$collection,
function ($filepath) {
copy($filepath, Hyde::getSiteOutputPath('media/'.basename($filepath)));
}
Expand All @@ -80,7 +81,8 @@ protected function compilePagesForClass(string $pageClass): void
$collection = $this->router->getRoutesForModel($pageClass);

$this->withProgressBar(
$collection, $this->compileRoute()
$collection,
$this->compileRoute()
);

$this->newLine(2);
Expand Down Expand Up @@ -122,7 +124,7 @@ protected function askIfUnsafeDirectoryShouldBeEmptied(): bool
return $this->confirm(sprintf(
'The configured output directory (%s) is potentially unsafe to empty. '.
'Are you sure you want to continue?',
Hyde::getSiteOutputPath())
);
Hyde::getSiteOutputPath()
));
}
}
8 changes: 4 additions & 4 deletions packages/framework/src/Services/DiscoveryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ public static function getDocumentationPageFiles(): array
public static function getMediaAssetFiles(): array
{
return glob(Hyde::path('_media/*.{'.str_replace(
' ',
'',
config('hyde.media_extensions', 'png,svg,jpg,jpeg,gif,ico,css,js')
).'}'), GLOB_BRACE);
' ',
'',
config('hyde.media_extensions', 'png,svg,jpg,jpeg,gif,ico,css,js')
).'}'), GLOB_BRACE);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/src/Services/RoutingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function getRoutesForModel(string $pageClass): Collection

/**
* This internal method adds the specified route to the route index.
* It's made publics so package developers can hook into the routing system.
* It's made public so package developers can hook into the routing system.
*/
public function addRoute(RouteContract $route): self
{
Expand Down
6 changes: 6 additions & 0 deletions packages/framework/src/Services/RssFeedService.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

/** @noinspection PhpComposerExtensionStubsInspection */

namespace Hyde\Framework\Services;

use Hyde\Framework\Helpers\Features;
Expand All @@ -18,6 +20,10 @@ class RssFeedService

public function __construct()
{
if (! extension_loaded('simplexml') || config('testing.mock_disabled_extensions', false) === true) {
throw new \Exception('The ext-simplexml extension is not installed, but is required to generate RSS feeds.');
}

$this->feed = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" />');
$this->feed->addChild('channel');
Expand Down
6 changes: 6 additions & 0 deletions packages/framework/src/Services/SitemapService.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

/** @noinspection PhpComposerExtensionStubsInspection */

namespace Hyde\Framework\Services;

use Hyde\Framework\Contracts\RouteContract;
Expand All @@ -23,6 +25,10 @@ class SitemapService

public function __construct()
{
if (! extension_loaded('simplexml') || config('testing.mock_disabled_extensions', false) === true) {
throw new \Exception('The ext-simplexml extension is not installed, but is required to generate RSS feeds.');
}

$this->time_start = microtime(true);

$this->xmlElement = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9"></urlset>');
Expand Down
4 changes: 2 additions & 2 deletions packages/framework/src/Services/ValidationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Hyde\Framework\Models\ValidationResult as Result;

/**
* @see \Hyde\Testing\Feature\Services\ValidationServiceTest
* @see \Hyde\Testing\Feature\Commands\HydeValidateCommandTest
* @see \Hyde\Framework\Testing\Feature\Services\ValidationServiceTest
* @see \Hyde\Framework\Testing\Feature\Commands\HydeValidateCommandTest
*/
class ValidationService
{
Expand Down
4 changes: 3 additions & 1 deletion packages/framework/src/Views/Components/LinkComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Hyde\Framework\Views\Components;

use Hyde\Framework\Hyde;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;

class LinkComponent extends Component
Expand All @@ -14,7 +16,7 @@ public function __construct(string $href)
$this->href = Hyde::relativeLink($href);
}

public function render(): \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
public function render(): View|Factory
{
return view('hyde::components.link');
}
Expand Down
Loading

0 comments on commit ba6b1e1

Please sign in to comment.