-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from codelicia/report
Add checkstyle output
- Loading branch information
Showing
13 changed files
with
234 additions
and
24 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Codelicia\Xulieta\Output; | ||
|
||
use Codelicia\Xulieta\ValueObject\Violation; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use function htmlspecialchars; | ||
|
||
final class Checkstyle implements OutputFormatter | ||
{ | ||
private OutputInterface $output; | ||
|
||
public function __construct(OutputInterface $output) | ||
{ | ||
$this->output = $output; | ||
$this->output->writeln('<?xml version="1.0" encoding="UTF-8"?>'); | ||
$this->output->writeln('<checkstyle>'); | ||
} | ||
|
||
public function addViolation(Violation $violation) : void | ||
{ | ||
$this->output->writeln(' <file name="' . htmlspecialchars($violation->file()) . '">'); | ||
|
||
$error = ' '; | ||
$error .= '<error'; | ||
$error .= ' line="' . $violation->absoluteLine() . '"'; | ||
$error .= ' column="1"'; | ||
$error .= ' severity="error"'; | ||
$error .= ' message="Codelicia/Xulieta: ' . htmlspecialchars($violation->message()) . '"'; | ||
$error .= ' source="Codelicia/Xulieta"'; | ||
$error .= '/>'; | ||
|
||
$this->output->writeln($error); | ||
$this->output->writeln(' </file>'); | ||
} | ||
|
||
public function __destruct() | ||
{ | ||
echo '</checkstyle>'; | ||
} | ||
|
||
public function writeln(string $text) : void | ||
{ | ||
// Intentionally left empty | ||
} | ||
} |
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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Codelicia\Xulieta\Output; | ||
|
||
use Codelicia\Xulieta\ValueObject\Violation; | ||
|
||
interface OutputFormatter | ||
{ | ||
public function addViolation(Violation $violation) : void; | ||
|
||
public function writeln(string $text) : void; | ||
} |
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,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Codelicia\Xulieta\Output; | ||
|
||
use Codelicia\Xulieta\ValueObject\Violation; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use const PHP_EOL; | ||
|
||
final class Stdout implements OutputFormatter | ||
{ | ||
private OutputInterface $output; | ||
|
||
public function __construct(OutputInterface $output) | ||
{ | ||
$this->output = $output; | ||
} | ||
|
||
public function addViolation(Violation $violation) : void | ||
{ | ||
$this->writeln('<error>Wrong code on file: ' . $violation->code()->file() . '</error>'); | ||
$this->writeln($violation->message() . PHP_EOL); | ||
$this->writeln($violation->code()->code()); | ||
} | ||
|
||
public function writeln(string $text) : void | ||
{ | ||
$this->output->writeln($text); | ||
} | ||
} |
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
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
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,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Codelicia\Xulieta\ValueObject; | ||
|
||
final class Violation | ||
{ | ||
private SampleCode $code; | ||
private string $message; | ||
private int $violationLine; | ||
|
||
public function __construct( | ||
SampleCode $code, | ||
string $message, | ||
int $violationLine = 0 | ||
) { | ||
$this->code = $code; | ||
$this->message = $message; | ||
$this->violationLine = $violationLine; | ||
} | ||
|
||
public function code() : SampleCode | ||
{ | ||
return $this->code; | ||
} | ||
|
||
public function file() : string | ||
{ | ||
return $this->code->file(); | ||
} | ||
|
||
public function violationLine() : int | ||
{ | ||
return $this->violationLine; | ||
} | ||
|
||
public function message() : string | ||
{ | ||
return $this->message; | ||
} | ||
|
||
public function absoluteLine() : int | ||
{ | ||
return $this->code()->position() + $this->violationLine(); | ||
} | ||
} |
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,10 @@ | ||
This code has a missing semi comma on the echo statement. | ||
|
||
```php | ||
<?php | ||
|
||
if (true) { | ||
echo 'Hello World!' | ||
} | ||
``` | ||
|
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,16 @@ | ||
--TEST-- | ||
Report a warning using checkstyle in case of missing PHP open tag | ||
--FILE-- | ||
<?php | ||
|
||
$checkRunner = require __DIR__ . '/init.php'; | ||
|
||
$checkRunner('tests/assets/syntax-error-checkstyle.md --output=checkstyle'); | ||
|
||
--EXPECTF-- | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<checkstyle> | ||
<file name="tests/assets/syntax-error-checkstyle.md"> | ||
<error line="7" column="1" severity="error" message="Codelicia/Xulieta: Syntax error, unexpected '}', expecting ';' on line 5" source="Codelicia/Xulieta"/> | ||
</file> | ||
</checkstyle> |