Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
20 changes: 14 additions & 6 deletions src/Command/AnalyzeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ protected function configure()
->setName('analyze')
->setDescription('Analyze code')
->addOption(
'files',
'project',
null,
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
'File(s) to avalyze'
InputOption::VALUE_OPTIONAL,
'Project name must be (php, symfony, drupal) or could be empty if a phpqa.yml or phpqa.yml.dist exists at current directory.'
)
->addOption(
'project',
'files',
null,
InputOption::VALUE_REQUIRED,
'Project name'
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
'File(s) to analyze'
);
}

Expand All @@ -49,6 +49,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
* @var \JMOlivas\Phpqa\Config $config
*/
$config = $application->getConfig();

if (!$project && !$config->isCustom()) {
throw new \Exception(
'No local phpqa.yml or phpqa.yml.dist at current working directory ' .
'you must provide a valid project name (php, symfony or drupal)'
);
}

$config->loadProjectConfiguration($project);

$this->directory = $application->getApplicationDirectory();
Expand Down
21 changes: 18 additions & 3 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@

class Config
{
/**
* @var array
*/
protected $config;

protected $custom = false;
/**
* @var boolean
*/
protected $custom;

public function __construct()
{
$this->custom = false;
$this->config = [];
$this->loadFile(__DIR__.'/../'.'config.yml');
$this->loadFile(__DIR__.'/../'.'phpqa.yml');
if ($this->getApplicationConfigFile()) {
$this->loadFile($this->getApplicationConfigFile());
$this->custom = true;
Expand Down Expand Up @@ -98,7 +105,7 @@ public function getApplicationConfigFile()

public function loadProjectConfiguration($project)
{
if ($this->custom) {
if ($this->isCustom()) {
return;
}

Expand Down Expand Up @@ -155,4 +162,12 @@ public function getProjectAnalyzerConfigFile($project, $analyzer)

return '--'.$analyserConfigOption.'='.$analyserConfigFile;
}

/**
* @return boolean
*/
public function isCustom()
{
return $this->custom;
}
}