Skip to content
Open
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/phphound/
/build/
/vendor/
composer.lock
composer.lock
.idea/
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
}
],
"require": {
"ext-json":"*",
"squizlabs/php_codesniffer": "2.*",
"sebastian/phpcpd": "2.*",
"phpmd/phpmd": "2.2.*",
Expand Down
22 changes: 11 additions & 11 deletions src/Analyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Analyser
* @param string[] $analysedPaths target file or directory path.
* @param string[] $ignoredPaths comma separated list of ignored directories.
*/
public function __construct(AbstractOutput $output, $binariesPath, $analysedPaths, $ignoredPaths)
public function __construct(AbstractOutput $output, string $binariesPath, array $analysedPaths, array $ignoredPaths)
{
$this->output = $output;
$this->binariesPath = $binariesPath;
Expand All @@ -66,7 +66,7 @@ public function __construct(AbstractOutput $output, $binariesPath, $analysedPath
* Run each configured PHP analysis tool.
* @return boolean true if it didn't find code issues.
*/
public function run()
public function run() : bool
{
$result = $this->createResult();
$this->trigger(
Expand All @@ -89,7 +89,7 @@ public function run()
$this->output->result($result);
$this->trigger(self::EVENT_FINISHED_ANALYSIS);

return !$result->hasIssues();
return ! $result->hasIssues();
}

/**
Expand All @@ -98,7 +98,7 @@ public function run()
* @param string|null $message optional message.
* @return void
*/
protected function trigger($event, $message = null)
protected function trigger(int $event, $message = null) : void
{
if ($this->output instanceof TriggerableInterface) {
$this->output->trigger($event, $message);
Expand All @@ -109,7 +109,7 @@ protected function trigger($event, $message = null)
* Get a list of paths to be ignored by the analysis.
* @return string[] a list of file and/or directory paths.
*/
public function getIgnoredPaths()
public function getIgnoredPaths() : array
{
return $this->ignoredPaths;
}
Expand All @@ -118,7 +118,7 @@ public function getIgnoredPaths()
* Analysis target path.
* @return string[] target path.
*/
public function getAnalysedPaths()
public function getAnalysedPaths() : array
{
return $this->analysedPaths;
}
Expand All @@ -127,7 +127,7 @@ public function getAnalysedPaths()
* Add an output filter to delegate to the analysis result object.
* @param OutputFilterInterface $filter filter instance.
*/
public function setResultsFilter(OutputFilterInterface $filter)
public function setResultsFilter(OutputFilterInterface $filter) : void
{
$this->resultsFilter = $filter;
}
Expand All @@ -137,7 +137,7 @@ public function setResultsFilter(OutputFilterInterface $filter)
* @param string[] $paths target paths.
* @return void
*/
public function setAnalysedPaths(array $paths)
public function setAnalysedPaths(array $paths) : void
{
$this->analysedPaths = $paths;
}
Expand All @@ -146,7 +146,7 @@ public function setAnalysedPaths(array $paths)
* List of PHP analys integration classes.
* @return string[] array of class names.
*/
protected function getAnalysisToolsClasses()
protected function getAnalysisToolsClasses() : string
{
return [
'phphound\integration\PHPCodeSniffer',
Expand All @@ -159,7 +159,7 @@ protected function getAnalysisToolsClasses()
* Set of PHP analys integration objects.
* @return phphound\integration\AbstractIntegration[] set of objects.
*/
protected function getAnalysisTools()
protected function getAnalysisTools() : array
{
$objects = [];

Expand All @@ -176,7 +176,7 @@ protected function getAnalysisTools()
* Create an empty analysis result.
* @return AnalysisResult instance.
*/
protected function createResult()
protected function createResult() : AnalysisResult
{
return new AnalysisResult;
}
Expand Down
13 changes: 6 additions & 7 deletions src/AnalysisResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AnalysisResult
* @param string $message Issue description.
* @return void
*/
public function addIssue($fileName, $line, $toolName, $issueType, $message)
public function addIssue(string $fileName, int $line, string $toolName, string $issueType, string $message) : void
{
if (!isset($this->data[$fileName])) {
$this->data[$fileName] = [];
Expand All @@ -50,11 +50,10 @@ public function addIssue($fileName, $line, $toolName, $issueType, $message)
* Check if there are any code issues.
* @return boolean true if there are issues.
*/
public function hasIssues()
public function hasIssues() : bool
{
// Required by PHP 5.4
$array = $this->toArray();
return !empty($array);
return ! empty($this->toArray());
}

/**
Expand All @@ -70,7 +69,7 @@ public function hasIssues()
* </code>
* @return array result daya.
*/
public function toArray()
public function toArray() : array
{
$data = [];

Expand All @@ -93,7 +92,7 @@ public function toArray()
* @param AnalysisResult $other another analysis result object.
* @return AnalysisResult returns itself.
*/
public function mergeWith(AnalysisResult $other)
public function mergeWith(AnalysisResult $other) : AnalysisResult
{
foreach ($other->toArray() as $fileName => $lines) {
foreach ($lines as $line => $issues) {
Expand All @@ -115,7 +114,7 @@ public function mergeWith(AnalysisResult $other)
* Add an output filter to delegate to the analysis result object.
* @param OutputFilterInterface $filter filter instance.
*/
public function setResultsFilter(OutputFilterInterface $filter)
public function setResultsFilter(OutputFilterInterface $filter) : void
{
$this->filter = $filter;
}
Expand Down
32 changes: 16 additions & 16 deletions src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Command
* @param string $binariesPath Composer binaries path.
* @param array $arguments command line arguments.
*/
public function __construct(CLImate $climate, $binariesPath, array $arguments)
public function __construct(CLImate $climate, string $binariesPath, array $arguments)
{
$this->cli = $climate;
$this->cli->description($this->getDescription());
Expand All @@ -66,7 +66,7 @@ public function __construct(CLImate $climate, $binariesPath, array $arguments)
* Run PHP-Hound command.
* @return boolean true if it didn't find code issues or ran successfully.
*/
public function run()
public function run() : bool
{
if ($this->hasArgumentValue('help')) {
$this->cli->usage();
Expand Down Expand Up @@ -95,7 +95,7 @@ public function run()
* @param string $gitDiff git diff arguments.
* @return DiffOutputFilter filter instance.
*/
protected function getGitDiffFilter($gitDiff)
protected function getGitDiffFilter(string $gitDiff) : DiffOutputFilter
{
$analysedPaths = $this->getAnalysedPaths();
$gitPath = array_shift($analysedPaths);
Expand All @@ -117,7 +117,7 @@ protected function getGitDiffFilter($gitDiff)
* @throws UnexpectedValueException on invalid format value.
* @return AbstractOutput
*/
protected function getOutput()
protected function getOutput() : AbstractOutput
{
$format = $this->getOutputFormat();
$formatClasses = $this->getOutputFormatClasses();
Expand All @@ -140,7 +140,7 @@ protected function getOutput()
* Command line arguments list for CLImate.
* @return array CLI list of arguments.
*/
protected function getArguments()
protected function getArguments() : array
{
return [
'help' => [
Expand Down Expand Up @@ -187,7 +187,7 @@ protected function getArguments()
* Get a list of paths to be ignored by the analysis.
* @return string[] a list of file and/or directory paths.
*/
public function getIgnoredPaths()
public function getIgnoredPaths() : array
{
$ignoredArgument = $this->getArgumentValue('ignore');
$ignoredPaths = explode(',', $ignoredArgument);
Expand All @@ -199,7 +199,7 @@ public function getIgnoredPaths()
* @param string $pathsString the path argument value.
* @return void
*/
protected function setAnalysedPathsFromString($pathsString)
protected function setAnalysedPathsFromString(string $pathsString) : void
{
$rawAnalysedPaths = explode(',', $pathsString);
$analysedPaths = array_filter($rawAnalysedPaths);
Expand All @@ -211,7 +211,7 @@ protected function setAnalysedPathsFromString($pathsString)
* @param string[] $paths target paths.
* @return void
*/
protected function setAnalysedPaths(array $paths)
protected function setAnalysedPaths(array $paths) : void
{
foreach ($paths as &$path) {
if (0 === strpos($path, DIRECTORY_SEPARATOR)) {
Expand All @@ -226,7 +226,7 @@ protected function setAnalysedPaths(array $paths)
* Analysis target paths.
* @return string[] a list of analysed paths (usually just one).
*/
public function getAnalysedPaths()
public function getAnalysedPaths() : array
{
return $this->analysedPaths;
}
Expand All @@ -235,7 +235,7 @@ public function getAnalysedPaths()
* Running script path.
* @return string current script directory.
*/
public function getWorkingDirectory()
public function getWorkingDirectory() : string
{
return getcwd();
}
Expand All @@ -244,7 +244,7 @@ public function getWorkingDirectory()
* Output format.
* @return string format type.
*/
public function getOutputFormat()
public function getOutputFormat() : string
{
return $this->getArgumentValue('format');
}
Expand All @@ -253,7 +253,7 @@ public function getOutputFormat()
* CLI output description.
* @return string description.
*/
public function getDescription()
public function getDescription() : string
{
return 'PHP Hound ' . Analyser::VERSION;
}
Expand All @@ -262,7 +262,7 @@ public function getDescription()
* Analyser instance.
* @return Analyser instance.
*/
public function getAnalyser()
public function getAnalyser() : Analyser
{
if (null === $this->analyser) {
$this->analyser = new Analyser(
Expand All @@ -279,7 +279,7 @@ public function getAnalyser()
* List of output format classes.
* @return array array where the key is a format and its value the class.
*/
protected function getOutputFormatClasses()
protected function getOutputFormatClasses() : array
{
return [
'text' => 'phphound\output\TextOutput',
Expand All @@ -295,7 +295,7 @@ protected function getOutputFormatClasses()
* @param string $name argument name.
* @return Mixed argument value.
*/
protected function getArgumentValue($name)
protected function getArgumentValue(string $name)
{
return $this->cli->arguments->get($name);
}
Expand All @@ -305,7 +305,7 @@ protected function getArgumentValue($name)
* @param string $name argument name.
* @return boolean if the argument has informed or not.
*/
protected function hasArgumentValue($name)
protected function hasArgumentValue(string $name) : bool
{
return $this->cli->arguments->defined($name, $this->arguments);
}
Expand Down
2 changes: 1 addition & 1 deletion src/helper/ArrayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ArrayHelper
* @param Mixed $value value to be verified.
* @return array value itself or an empty array.
*/
public static function ensure($value)
public static function ensure($value) : array
{
if (empty($value) || !is_array($value)) {
return [];
Expand Down
Loading