Skip to content

Commit

Permalink
Merge pull request #474 from phpmetrics/fixes_permissions_path
Browse files Browse the repository at this point in the history
Fixes issues with paths
  • Loading branch information
Halleck45 authored Mar 24, 2022
2 parents 6e1b0d6 + dfb7250 commit ac7b10d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
21 changes: 14 additions & 7 deletions src/Hal/Application/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Hal\Application;

use Exception;
use Hal\Application\Config\ConfigException;
use Hal\Application\Config\Parser;
use Hal\Application\Config\Validator;
Expand Down Expand Up @@ -87,13 +88,19 @@ public function run(array $argv)
(new ViolationParser($config, $output))->apply($metrics);

// report
(new Report\Cli\Reporter($config, $output))->generate($metrics);
(new Report\Cli\SearchReporter($config, $output))->generate($metrics);
(new Report\Html\Reporter($config, $output))->generate($metrics);
(new Report\Csv\Reporter($config, $output))->generate($metrics);
(new Report\Json\Reporter($config, $output))->generate($metrics);
(new Report\Json\SummaryReporter($config, $output))->generate($metrics);
(new Report\Violations\Xml\Reporter($config, $output))->generate($metrics);
try {
(new Report\Cli\Reporter($config, $output))->generate($metrics);
(new Report\Cli\SearchReporter($config, $output))->generate($metrics);
(new Report\Html\Reporter($config, $output))->generate($metrics);
(new Report\Csv\Reporter($config, $output))->generate($metrics);
(new Report\Json\Reporter($config, $output))->generate($metrics);
(new Report\Json\SummaryReporter($config, $output))->generate($metrics);
(new Report\Violations\Xml\Reporter($config, $output))->generate($metrics);
} catch (Exception $e) {
$output->writeln(sprintf('<error>Cannot generate report: %s</error>', $e->getMessage()));
$output->writeln('');
exit(1);
}

// exit status
$shouldExitDueToCriticalViolationsCount = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/Hal/Application/Config/File/ConfigFileReaderJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ConfigFileReaderJson implements ConfigFileReaderInterface
/**
* @var string
*/
private $filename;
protected $filename;

/**
* @param string $filename
Expand Down
13 changes: 0 additions & 13 deletions src/Hal/Application/Config/File/ConfigFileReaderYaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,6 @@

class ConfigFileReaderYaml extends ConfigFileReaderJson implements ConfigFileReaderInterface
{
/**
* @var string
*/
private $filename;

/**
* @param string $filename
*/
public function __construct($filename)
{
$this->filename = $filename;
}

/**
* @param Config $config
*/
Expand Down
10 changes: 10 additions & 0 deletions src/Hal/Report/Html/Reporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Hal\Metric\Consolidated;
use Hal\Metric\Group\Group;
use Hal\Metric\Metrics;
use RuntimeException as RuntimeExceptionAlias;

class Reporter
{
Expand Down Expand Up @@ -103,6 +104,11 @@ public function generate(Metrics $metrics)
if (!file_exists($logDir . '/fonts')) {
mkdir($logDir . '/fonts', 0755, true);
}

if (!is_writable($logDir)) {
throw new RuntimeExceptionAlias(sprintf('Unable to write in the directory "%s"', $logDir));
}

recurse_copy($this->templateDir . '/html_report/js', $logDir . '/js');
recurse_copy($this->templateDir . '/html_report/css', $logDir . '/css');
recurse_copy($this->templateDir . '/html_report/images', $logDir . '/images');
Expand Down Expand Up @@ -193,6 +199,10 @@ public function generate(Metrics $metrics)
*/
public function renderPage($source, $destination, Consolidated $consolidated, $history)
{
if (!is_writable(dirname($destination))) {
throw new RuntimeExceptionAlias(sprintf('Unable to write in the directory "%s"', dirname($destination)));
}

$this->sum = $sum = $consolidated->getSum();
$this->avg = $avg = $consolidated->getAvg();
$this->classes = $classes = $consolidated->getClasses();
Expand Down

0 comments on commit ac7b10d

Please sign in to comment.