Skip to content

Commit

Permalink
Update copyright, fix tests, fix inspection issues
Browse files Browse the repository at this point in the history
  • Loading branch information
hollodotme committed Jan 28, 2020
1 parent a9cff8a commit 9097725
Show file tree
Hide file tree
Showing 28 changed files with 210 additions and 152 deletions.
14 changes: 9 additions & 5 deletions bin/main.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/**
* Copyright (c) 2016-2018 Holger Woltersdorf & Contributors
* Copyright (c) 2016-2020 Holger Woltersdorf & Contributors
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
Expand All @@ -19,14 +19,18 @@
use IceHawk\StaticPageGenerator\ConsoleCommands\GenerateSitemap;
use IceHawk\StaticPageGenerator\ConsoleCommands\RollBack;
use IceHawk\StaticPageGenerator\ConsoleCommands\SelfUpdate;
use Throwable;
use function define;
use function dirname;
use function get_class;

error_reporting( -1 );
ini_set( 'display_errors', 'On' );

require __DIR__ . '/../vendor/autoload.php';

\define( 'PHAR_DIR', \dirname( __DIR__ ) );
\define( 'WORKING_DIR', getcwd() );
define( 'PHAR_DIR', dirname( __DIR__ ) );
define( 'WORKING_DIR', getcwd() );

try
{
Expand All @@ -44,9 +48,9 @@
$code = $app->run();
exit( $code );
}
catch ( \Throwable $e )
catch ( Throwable $e )
{
echo 'Uncaught ' . \get_class( $e ) . ' with message: ' . $e->getMessage() . "\n";
echo 'Uncaught ' . get_class( $e ) . ' with message: ' . $e->getMessage() . "\n";
echo $e->getTraceAsString();
exit( 1 );
}
19 changes: 11 additions & 8 deletions src/ConsoleCommands/AbstractConsoleCommand.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/**
* Copyright (c) 2016-2018 Holger Woltersdorf & Contributors
* Copyright (c) 2016-2020 Holger Woltersdorf & Contributors
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
Expand All @@ -17,6 +17,7 @@
use IceHawk\StaticPageGenerator\Exceptions\ConfigNotFound;
use IceHawk\StaticPageGenerator\StaticPageGenerator;
use Symfony\Component\Console\Command\Command;
use function dirname;

/**
* Class AbstractConsoleCommand
Expand All @@ -25,13 +26,15 @@
*/
abstract class AbstractConsoleCommand extends Command
{
public function getEnv(): StaticPageGenerator
public function getEnv() : StaticPageGenerator
{
/** @var StaticPageGenerator $spg */
return $this->getApplication();
$spg = $this->getApplication();

return $spg;
}

final protected function getFullPath( string $dir, string $file ): string
final protected function getFullPath( string $dir, string $file ) : string
{
return rtrim( $dir, DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . ltrim( $file, DIRECTORY_SEPARATOR );
}
Expand All @@ -40,10 +43,10 @@ final protected function getFullPath( string $dir, string $file ): string
* @param string $configPath
* @param array $overwrites
*
* @return \IceHawk\StaticPageGenerator\ConsoleCommands\Configs\ProjectConfig
* @throws \IceHawk\StaticPageGenerator\Exceptions\ConfigNotFound
* @return ProjectConfig
* @throws ConfigNotFound
*/
final protected function loadConfig( string $configPath, array $overwrites ): ProjectConfig
final protected function loadConfig( string $configPath, array $overwrites ) : ProjectConfig
{
if ( $configPath[0] !== '/' )
{
Expand All @@ -58,6 +61,6 @@ final protected function loadConfig( string $configPath, array $overwrites ): Pr
$configData = json_decode( file_get_contents( $configPath ), true );
$configData = array_merge( $configData, $overwrites );

return new ProjectConfig( \dirname( $configPath ), $configData );
return new ProjectConfig( dirname( $configPath ), $configData );
}
}
46 changes: 26 additions & 20 deletions src/ConsoleCommands/CheckLinks.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);
<?php declare(strict_types=1);
/**
* Copyright (c) 2016-2018 Holger Woltersdorf & Contributors
* Copyright (c) 2016-2020 Holger Woltersdorf & Contributors
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
Expand All @@ -13,8 +13,10 @@

namespace IceHawk\StaticPageGenerator\ConsoleCommands;

use Exception;
use IceHawk\StaticPageGenerator\ConsoleCommands\Configs\ProjectConfig;
use IceHawk\StaticPageGenerator\Exceptions\ConfigNotFound;
use IceHawk\StaticPageGenerator\Exceptions\DirectoryNotFound;
use IceHawk\StaticPageGenerator\Formatters\ByteFormatter;
use IceHawk\StaticPageGenerator\LinkCheckers\HtmlLinkChecker;
use IceHawk\StaticPageGenerator\LinkCheckers\XmlSitemapLinkChecker;
Expand All @@ -24,6 +26,7 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use function count;

/**
* Class CheckLinks
Expand All @@ -36,16 +39,21 @@ final class CheckLinks extends AbstractConsoleCommand

protected function configure() : void
{
/** @noinspection UnusedFunctionResultInspection */
$this->setDescription( 'Checks links in generated output.' );
/** @noinspection UnusedFunctionResultInspection */
$this->addOption( 'baseUrl', 'b', InputOption::VALUE_OPTIONAL, 'Overwrites baseUrl setting in Project.json' );
/** @noinspection UnusedFunctionResultInspection */
$this->addOption( 'generate', 'g', InputOption::VALUE_NONE, 'Generate output before checking links.' );
/** @noinspection UnusedFunctionResultInspection */
$this->addOption(
'timeout',
't',
InputOption::VALUE_OPTIONAL,
'Defines the timeout in seconds to wait for each link.',
5
);
/** @noinspection UnusedFunctionResultInspection */
$this->addArgument(
'config',
InputArgument::OPTIONAL,
Expand All @@ -55,11 +63,11 @@ protected function configure() : void
}

/**
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int
* @throws \Exception
* @throws Exception
*/
protected function execute( InputInterface $input, OutputInterface $output ) : int
{
Expand All @@ -86,10 +94,8 @@ protected function execute( InputInterface $input, OutputInterface $output ) : i
]
);

$generateCommands = $this->getEnv()->all( 'generate' );

/** @var AbstractConsoleCommand $command */
foreach ( $generateCommands as $command )
foreach ( $this->getEnv()->all( 'generate' ) as $command )
{
$command->run( clone $generateInput, $output );
}
Expand Down Expand Up @@ -137,11 +143,11 @@ private function getOverwrites( InputInterface $input ) : array
}

/**
* @param \IceHawk\StaticPageGenerator\ConsoleCommands\Configs\ProjectConfig $projectConfig
* @param int $readTimeout
* @param ProjectConfig $projectConfig
* @param int $readTimeout
*
* @return int
* @throws \IceHawk\StaticPageGenerator\Exceptions\DirectoryNotFound
* @throws DirectoryNotFound
*/
private function checkHtmlLinks( ProjectConfig $projectConfig, int $readTimeout ) : int
{
Expand All @@ -160,7 +166,7 @@ private function checkHtmlLinks( ProjectConfig $projectConfig, int $readTimeout
{
$this->style->text( '' );
$this->style->text( '<fg=red>!! Some HTML links seem to be broken:</>' );
$headers = [ 'Filepath', 'Link', 'Response' ];
$headers = ['Filepath', 'Link', 'Response'];
$this->style->table( $headers, $failedLinks );
}
else
Expand All @@ -176,13 +182,13 @@ private function checkHtmlLinks( ProjectConfig $projectConfig, int $readTimeout
{
$this->style->text( '' );
$this->style->text( '<fg=yellow>Some HTML links have been skipped:</>' );
$headers = [ 'Filepath', 'Link', 'Reason' ];
$headers = ['Filepath', 'Link', 'Reason'];
$this->style->table( $headers, $skippedLinks );
$this->style->text( '' );
}
else
{
$skippedLinksCount = \count( $skippedLinks );
$skippedLinksCount = count( $skippedLinks );
$this->style->text( '' );
$this->style->text( "<fg=yellow>{$skippedLinksCount} HTML links have been skipped.</>" );
$this->style->text( '' );
Expand All @@ -193,11 +199,11 @@ private function checkHtmlLinks( ProjectConfig $projectConfig, int $readTimeout
}

/**
* @param \IceHawk\StaticPageGenerator\ConsoleCommands\Configs\ProjectConfig $projectConfig
* @param int $readTimeout
* @param ProjectConfig $projectConfig
* @param int $readTimeout
*
* @return int
* @throws \IceHawk\StaticPageGenerator\Exceptions\DirectoryNotFound
* @throws DirectoryNotFound
*/
private function checkXmlSitemapLinks( ProjectConfig $projectConfig, int $readTimeout ) : int
{
Expand All @@ -216,7 +222,7 @@ private function checkXmlSitemapLinks( ProjectConfig $projectConfig, int $readTi
{
$this->style->text( '' );
$this->style->text( '<fg=red>!! Some Sitemap links seem to be broken:</>' );
$headers = [ 'Filepath', 'Link', 'Response' ];
$headers = ['Filepath', 'Link', 'Response'];
$this->style->table( $headers, $failedLinks );
}
else
Expand All @@ -232,13 +238,13 @@ private function checkXmlSitemapLinks( ProjectConfig $projectConfig, int $readTi
{
$this->style->text( '' );
$this->style->text( '<fg=yellow>Some Sitemap links have been skipped:</>' );
$headers = [ 'Filepath', 'Link', 'Reason' ];
$headers = ['Filepath', 'Link', 'Reason'];
$this->style->table( $headers, $skippedLinks );
$this->style->text( '' );
}
else
{
$skippedLinksCount = \count( $skippedLinks );
$skippedLinksCount = count( $skippedLinks );
$this->style->text( '' );
$this->style->text( "<fg=yellow>{$skippedLinksCount} Sitemap links have been skipped.</>" );
$this->style->text( '' );
Expand Down
2 changes: 1 addition & 1 deletion src/ConsoleCommands/Configs/PageConfig.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);
/**
* Copyright (c) 2016-2018 Holger Woltersdorf & Contributors
* Copyright (c) 2016-2020 Holger Woltersdorf & Contributors
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
Expand Down
Loading

0 comments on commit 9097725

Please sign in to comment.