-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08282b6
commit d2f5fc0
Showing
9 changed files
with
222 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,5 +20,8 @@ | |
"psr-4": { | ||
"NdB\\PhpDocCheck\\": "src" | ||
} | ||
}, | ||
"require-dev": { | ||
"squizlabs/php_codesniffer": "^3.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0"?> | ||
<ruleset name="php-doc-check standard" namespace="NdB"> | ||
<file>./src</file> | ||
<file>./bin/php-doc-check</file> | ||
<exclude-pattern>*/vendor/*</exclude-pattern> | ||
<rule ref="PSR2"/> | ||
</ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,38 @@ | ||
<?php | ||
namespace NdB\PhpDocCheck; | ||
|
||
class AnalysableFile{ | ||
public $has_errors = false; | ||
public $has_warnings = false; | ||
public $findings = array(); | ||
class AnalysableFile | ||
{ | ||
public $has_errors = false; | ||
public $has_warnings = false; | ||
public $findings = array(); | ||
|
||
public function __construct(\SplFileInfo $file, \PhpParser\Parser $parser, $arguments){ | ||
$this->file = $file; | ||
$this->parser = $parser; | ||
$this->arguments = $arguments; | ||
} | ||
public function __construct(\SplFileInfo $file, \PhpParser\Parser $parser, $arguments) | ||
{ | ||
$this->file = $file; | ||
$this->parser = $parser; | ||
$this->arguments = $arguments; | ||
} | ||
|
||
public function analyse(){ | ||
$statements = $this->parser->parse(file_get_contents($this->file->getRealPath())); | ||
$traverser = new \PhpParser\NodeTraverser(); | ||
$traverser->addVisitor(new \NdB\PhpDocCheck\NodeVisitor($this)); | ||
$traverser->traverse($statements); | ||
return $this->getProgressIndicator(); | ||
} | ||
public function analyse() | ||
{ | ||
$statements = $this->parser->parse(file_get_contents($this->file->getRealPath())); | ||
$traverser = new \PhpParser\NodeTraverser(); | ||
$traverser->addVisitor(new \NdB\PhpDocCheck\NodeVisitor($this)); | ||
$traverser->traverse($statements); | ||
return $this->getProgressIndicator(); | ||
} | ||
|
||
/** | ||
* Gives a visual progression value, based on analysis result | ||
*/ | ||
public function getProgressIndicator() : string{ | ||
if(!$this->has_warnings && !$this->has_errors ){ | ||
return '.'; | ||
}elseif(!$this->has_errors){ | ||
return 'W'; | ||
} | ||
return 'E'; | ||
} | ||
} | ||
/** | ||
* Gives a visual progression value, based on analysis result | ||
*/ | ||
public function getProgressIndicator() : string | ||
{ | ||
if (!$this->has_warnings && !$this->has_errors) { | ||
return '.'; | ||
} elseif (!$this->has_errors) { | ||
return 'W'; | ||
} | ||
return 'E'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
<?php | ||
namespace NdB\PhpDocCheck\Findings; | ||
|
||
class Error extends Warning{ | ||
public function getType():string{ | ||
return 'Error'; | ||
} | ||
} | ||
class Error extends Warning | ||
{ | ||
public function getType():string | ||
{ | ||
return 'Error'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
<?php | ||
namespace NdB\PhpDocCheck\Findings; | ||
|
||
class Warning{ | ||
public function __construct(string $message, int $line){ | ||
$this->message = $message; | ||
$this->line = $line; | ||
} | ||
class Warning | ||
{ | ||
public function __construct(string $message, int $line) | ||
{ | ||
$this->message = $message; | ||
$this->line = $line; | ||
} | ||
|
||
public function getType():string{ | ||
return 'Warning'; | ||
} | ||
public function getLine():int{ | ||
return $this->line; | ||
} | ||
public function getMessage():string{ | ||
return $this->message; | ||
} | ||
} | ||
public function getType():string | ||
{ | ||
return 'Warning'; | ||
} | ||
public function getLine():int | ||
{ | ||
return $this->line; | ||
} | ||
public function getMessage():string | ||
{ | ||
return $this->message; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,29 @@ | ||
<?php | ||
namespace NdB\PhpDocCheck\Output; | ||
|
||
abstract class AbstractOutput{ | ||
public function __construct(array $files){ | ||
$this->files = $files; | ||
} | ||
abstract class AbstractOutput | ||
{ | ||
public function __construct(array $files) | ||
{ | ||
$this->files = $files; | ||
} | ||
|
||
public function display(){ | ||
echo $this->get(); | ||
} | ||
public function display() | ||
{ | ||
echo $this->get(); | ||
} | ||
|
||
/** | ||
* Determines if this scan has 'failed' and should be fixed. Or if it was | ||
* flawless. CI will fail when a non zero exit code is returned. | ||
*/ | ||
public function getExitCode(){ | ||
foreach($this->files as $file){ | ||
if($file->has_errors || $file->has_warnings){ | ||
return 1; | ||
} | ||
} | ||
return 0; | ||
} | ||
} | ||
/** | ||
* Determines if this scan has 'failed' and should be fixed. Or if it was | ||
* flawless. CI will fail when a non zero exit code is returned. | ||
*/ | ||
public function getExitCode() | ||
{ | ||
foreach ($this->files as $file) { | ||
if ($file->has_errors || $file->has_warnings) { | ||
return 1; | ||
} | ||
} | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
<?php | ||
namespace NdB\PhpDocCheck\Output; | ||
|
||
class Json{ | ||
public function get(){ | ||
$output = array(); | ||
foreach($this->files as $file){ | ||
if(!empty($file->findings)){ | ||
$output[] = array( | ||
'file'=>$file->file->getRealPath(), | ||
'findings'=>$file->findings, | ||
); | ||
} | ||
} | ||
return json_encode($output); | ||
} | ||
} | ||
class Json | ||
{ | ||
public function get() | ||
{ | ||
$output = array(); | ||
foreach ($this->files as $file) { | ||
if (!empty($file->findings)) { | ||
$output[] = array( | ||
'file'=>$file->file->getRealPath(), | ||
'findings'=>$file->findings, | ||
); | ||
} | ||
} | ||
return json_encode($output); | ||
} | ||
} |
Oops, something went wrong.