forked from qossmic/deptrac-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to define a custom mapper for the baseline store/load for…
… people that need/want to store the baseline differently. 2 use-cases immediately come to mind: - qossmic#45 (comment) - using different format for storing violation in the PHP configuration (currently you still need to load violations from a yaml file even when using PHP config file for Deptrac)
- Loading branch information
1 parent
4707e55
commit 5497d3c
Showing
9 changed files
with
121 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
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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Qossmic\Deptrac\Contract\OutputFormatter; | ||
|
||
interface BaselineMapperInterface | ||
{ | ||
/** | ||
* Maps a grouped list of violations to a format that will be stored to a | ||
* file by the `baseline` formatter. | ||
* | ||
* @param array<string,list<string>> $groupedViolations | ||
*/ | ||
public function fromPHPListToString(array $groupedViolations): string; | ||
|
||
/** | ||
* Load the existing violation to ignore by custom mapper logic. | ||
* | ||
* @return array<string,list<string>> | ||
*/ | ||
public function loadViolations(): array; | ||
} |
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,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Qossmic\Deptrac\Supportive\OutputFormatter; | ||
|
||
use Qossmic\Deptrac\Contract\OutputFormatter\BaselineMapperInterface; | ||
use Symfony\Component\Yaml\Yaml; | ||
|
||
final class YamlBaselineMapper implements BaselineMapperInterface | ||
{ | ||
/** | ||
* @param array<string, list<string>> $skippedViolations | ||
*/ | ||
public function __construct( | ||
private readonly array $skippedViolations, | ||
) {} | ||
|
||
public function fromPHPListToString(array $groupedViolations): string | ||
{ | ||
return Yaml::dump( | ||
[ | ||
'deptrac' => [ | ||
'skip_violations' => $groupedViolations, | ||
], | ||
], | ||
4, | ||
2 | ||
); | ||
} | ||
|
||
public function loadViolations(): array | ||
{ | ||
return $this->skippedViolations; | ||
} | ||
} |
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