Skip to content

Commit

Permalink
Merge pull request #433 from hydephp/analysis-KZEVr3
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
HydePHP authored May 20, 2022
2 parents 2d24525 + bc1e3ac commit a017c40
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 20 deletions.
9 changes: 4 additions & 5 deletions src/Actions/FindsContentLengthForImageObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ class FindsContentLengthForImageObject implements ActionContract
protected Image $image;

/**
* Testing adding console debug output
* Testing adding console debug output.
*/
protected OutputInterface $output;

public function __construct(Image $image)
{
$this->image = $image;

$this->output = new \Symfony\Component\Console\Output\ConsoleOutput();
}

Expand All @@ -48,7 +48,6 @@ protected function fetchRemoteImageInformation(): int
'User-Agent' => config('hyde.http_user_agent', 'RSS Request Client'),
])->head($this->image->getSource());


$headers = $response->headers();

if (array_key_exists('Content-Length', $headers)) {
Expand All @@ -60,7 +59,7 @@ protected function fetchRemoteImageInformation(): int
$this->write(' <fg=gray> Is the image path valid? '.($this->image->getSource()).'</>');

return 0;
}
}

protected function fetchLocalImageInformation(): int
{
Expand All @@ -78,4 +77,4 @@ protected function write(string $string): void
{
$this->output->writeln($string);
}
}
}
11 changes: 6 additions & 5 deletions src/Commands/HydeBuildRssFeedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,31 @@ class HydeBuildRssFeedCommand extends Command
*/
public function handle(): int
{
$actionTime = microtime(true);
$actionTime = microtime(true);

if (! $this->runPreflightCheck()) {
return 1;
}

$this->comment('Generating RSS feed...');
file_put_contents(Hyde::getSiteOutputPath(RssFeedService::getDefaultOutputFilename()), RssFeedService::generateFeed());
$this->line(' > Created <info>'.RssFeedService::getDefaultOutputFilename().'</> in '.$this->getExecutionTimeInMs($actionTime)."ms\n");
file_put_contents(Hyde::getSiteOutputPath(RssFeedService::getDefaultOutputFilename()), RssFeedService::generateFeed());
$this->line(' > Created <info>'.RssFeedService::getDefaultOutputFilename().'</> in '.$this->getExecutionTimeInMs($actionTime)."ms\n");

return 0;
}

protected function runPreflightCheck(): bool
{
if (! RssFeedService::canGenerateFeed()) {
$this->error('Cannot generate an RSS feed, please check your configuration.');

return false;
}

return true;
}

protected function getExecutionTimeInMs(float $timeStart): float
protected function getExecutionTimeInMs(float $timeStart): float
{
return number_format(((microtime(true) - $timeStart) * 1000), 2);
}
Expand Down
7 changes: 4 additions & 3 deletions src/Commands/HydeBuildSitemapCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,30 @@ class HydeBuildSitemapCommand extends Command
public function handle(): int
{
$actionTime = microtime(true);

if (! $this->runPreflightCheck()) {
return 1;
}

$this->comment('Generating sitemap...');
file_put_contents(Hyde::getSiteOutputPath('sitemap.xml'), SitemapService::generateSitemap());
$this->line(' > Created <info>sitemap.xml</> in '.$this->getExecutionTimeInMs($actionTime)."ms\n");

return 0;
}

protected function runPreflightCheck(): bool
{
if (! SitemapService::canGenerateSitemap()) {
$this->error('Cannot generate sitemap.xml, please check your configuration.');

return false;
}

return true;
}

protected function getExecutionTimeInMs(float $timeStart): float
protected function getExecutionTimeInMs(float $timeStart): float
{
return number_format(((microtime(true) - $timeStart) * 1000), 2);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Services/RssFeedService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Hyde\Framework\Services;

use Hyde\Framework\Hyde;
use Hyde\Framework\Helpers\Features;
use Hyde\Framework\Hyde;
use Hyde\Framework\Models\MarkdownPost;
use SimpleXMLElement;

Expand Down
1 change: 0 additions & 1 deletion tests/Feature/Commands/BuildStaticSiteCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ public function test_rss_feed_is_generated_when_conditions_are_met()
unlink(Hyde::path('_site/feed.xml'));
}


/**
* Added for code coverage, deprecated as the pretty flag is deprecated.
*
Expand Down
3 changes: 1 addition & 2 deletions tests/Feature/Commands/HydeBuildRssFeedCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
namespace Tests\Feature\Commands;

use Hyde\Framework\Hyde;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;

/**
* @covers \Hyde\Framework\Commands\HydeBuildRssFeedCommand
*/
class HydeBuildRssFeedCommandTest extends TestCase
{
public function test_rss_feed_is_not_generated_when_conditions_are_not_met()
public function test_rss_feed_is_not_generated_when_conditions_are_not_met()
{
config(['hyde.site_url' => '']);
config(['hyde.generateRssFeed' => false]);
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/Commands/HydeBuildSitemapCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function test_sitemap_is_not_generated_when_conditions_are_not_met()
unlinkIfExists(Hyde::path('_site/sitemap.xml'));

$this->artisan('build:sitemap')
->expectsOutput('Cannot generate sitemap.xml, please check your configuration.')
->expectsOutput('Cannot generate sitemap.xml, please check your configuration.')
->assertExitCode(1);

$this->assertFileDoesNotExist(Hyde::path('_site/sitemap.xml'));
Expand All @@ -31,7 +31,7 @@ public function test_sitemap_is_generated_when_conditions_are_met()
unlinkIfExists(Hyde::path('_site/sitemap.xml'));
$this->artisan('build:sitemap')
->expectsOutput('Generating sitemap...')
->expectsOutputToContain('Created sitemap.xml')
->expectsOutputToContain('Created sitemap.xml')
->assertExitCode(0);

$this->assertFileExists(Hyde::path('_site/sitemap.xml'));
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/FindsContentLengthForImageObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Tests\Feature;

use Hyde\Framework\Actions\FindsContentLengthForImageObject;
use Hyde\Framework\Models\Image;
use Illuminate\Http\Client\Request;
use Illuminate\Support\Facades\Http;
Expand All @@ -15,6 +14,7 @@ class FindsContentLengthForImageObjectTest extends TestCase
{
/**
* Unit test for the shorthand. Logic is tested in the rest of the case.
*
* @covers \Hyde\Framework\Models\Image::getContentLength
*/
public function test_image_helper_shorthand_returns_content_length()
Expand Down

0 comments on commit a017c40

Please sign in to comment.