Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COMOPS-908: Updating compatibility with the BIC doc generator #25

Merged
merged 2 commits into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "magento/magento-semver",
"description": "Magento semantic version checker",
"version": "2.0.0",
"version": "3.0.0",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
13 changes: 13 additions & 0 deletions src/Analyzer/AbstractCodeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,17 @@ protected function getFileName($context, $nodeName, $isBefore = true)
{
return $isBefore ? $this->fileBefore : $this->fileAfter;
}

/**
* Gets the AbstractCodeAnalyzers for content analysis (ex: method analyzer for classes)
*
* @param string $context
* @param string $fileBefore
* @param string $fileAfter
* @return array
*/
protected function getContentAnalyzers($context, $fileBefore, $fileAfter)
{
return [];
}
}
36 changes: 24 additions & 12 deletions src/Analyzer/ClassAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,8 @@ protected function reportChanged($report, $registryBefore, $registryAfter, $toVe
$classAfter = $afterNameMap[$key];

if ($classBefore !== $classAfter) {
/**
* @var AnalyzerInterface[] $analyzers
*/
$analyzers = [
new ClassMethodAnalyzer(static::CONTEXT, $fileBefore, $fileAfter, $this->dependencyGraph),
new PropertyAnalyzer(static::CONTEXT, $fileBefore, $fileAfter),
new ClassConstantAnalyzer(static::CONTEXT, $fileBefore, $fileAfter),
new ClassMethodExceptionAnalyzer(static::CONTEXT, $fileBefore, $fileAfter),
new ClassImplementsAnalyzer(static::CONTEXT, $fileBefore, $fileAfter),
new ClassExtendsAnalyzer(static::CONTEXT, $fileBefore, $fileAfter),
new ClassTraitAnalyzer(static::CONTEXT, $fileBefore, $fileAfter),
];
/** @var AnalyzerInterface[] $analyzers */
$analyzers = $this->getContentAnalyzers(static::CONTEXT, $fileBefore, $fileAfter);

foreach ($analyzers as $analyzer) {
$internalReport = $analyzer->analyze($classBefore, $classAfter);
Expand All @@ -129,6 +119,28 @@ protected function reportChanged($report, $registryBefore, $registryAfter, $toVe
}
}

/**
* Get the list of content analyzers
*
* @param string $context
* @param string $fileBefore
* @param string $fileAfter
* @return array
*/
protected function getContentAnalyzers($context, $fileBefore, $fileAfter)
{
return [
new ClassMethodAnalyzer($context, $fileBefore, $fileAfter, $this->dependencyGraph),
new PropertyAnalyzer($context, $fileBefore, $fileAfter),
new ClassConstantAnalyzer($context, $fileBefore, $fileAfter),
new ClassMethodExceptionAnalyzer($context, $fileBefore, $fileAfter),
new ClassImplementsAnalyzer($context, $fileBefore, $fileAfter),
new ClassExtendsAnalyzer($context, $fileBefore, $fileAfter),
new ClassTraitAnalyzer($context, $fileBefore, $fileAfter),
];
}


/**
* Get the class node registry
*
Expand Down
27 changes: 21 additions & 6 deletions src/Analyzer/InterfaceAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,7 @@ protected function reportChanged($report, $registryBefore, $registryAfter, $toVe

if ($interfaceBefore !== $interfaceAfter) {
/** @var AnalyzerInterface[] $analyzers */
$analyzers = [
new ClassMethodAnalyzer(static::CONTEXT, $fileBefore, $fileAfter),
new ClassConstantAnalyzer(static::CONTEXT, $fileBefore, $fileAfter),
new ClassMethodExceptionAnalyzer(static::CONTEXT, $fileBefore, $fileAfter),
new InterfaceExtendsAnalyzer(static::CONTEXT, $fileBefore, $fileAfter)
];
$analyzers = $this->getContentAnalyzers(static::CONTEXT, $fileBefore, $fileAfter);

foreach ($analyzers as $analyzer) {
$internalReport = $analyzer->analyze($interfaceBefore, $interfaceAfter);
Expand All @@ -133,4 +128,24 @@ protected function reportChanged($report, $registryBefore, $registryAfter, $toVe
}
}
}

/**
* Get the list of content analyzers
*
* @param string $context
* @param string $fileBefore
* @param string $fileAfter
* @return array
*/
protected function getContentAnalyzers($context, $fileBefore, $fileAfter)
{
return [
new ClassMethodAnalyzer($context, $fileBefore, $fileAfter),
new ClassConstantAnalyzer($context, $fileBefore, $fileAfter),
new ClassMethodExceptionAnalyzer($context, $fileBefore, $fileAfter),
new InterfaceExtendsAnalyzer($context, $fileBefore, $fileAfter)
];
}


}
19 changes: 16 additions & 3 deletions src/Analyzer/TraitAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ protected function reportChanged($report, $registryBefore, $registryAfter, $toVe
$fileAfter = $this->getFileName($registryAfter, $traitName);

/** @var AbstractCodeAnalyzer[] $analyzers */
$analyzers = [
new ClassMethodAnalyzer(static::CONTEXT, $fileBefore, $fileAfter),
];
$analyzers = $this->getContentAnalyzers(static::CONTEXT, $fileBefore, $fileAfter);

foreach ($analyzers as $analyzer) {
$internalReport = $analyzer->analyze($traitBefore, $traitAfter);
Expand All @@ -128,4 +126,19 @@ protected function reportChanged($report, $registryBefore, $registryAfter, $toVe
}
}
}

/**
* Get the list of content analyzers
*
* @param string $context
* @param string $fileBefore
* @param string $fileAfter
* @return array
*/
protected function getContentAnalyzers($context, $fileBefore, $fileAfter)
{
return [new ClassMethodAnalyzer($context, $fileBefore, $fileAfter)];
}


}
22 changes: 16 additions & 6 deletions src/DbSchemaReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,28 @@

class DbSchemaReport extends ReportAlias
{
public static $contexts = [
'class',
'function',
'interface',
'trait',
'database',
'di',
'layout',
'system',
'xsd',
'less'
];

/**
* Report constructor.
*/
public function __construct()
{
$levels = array_fill_keys(Level::asList(), []);
parent::__construct();
$this->differences['database'] = $levels;
$this->differences['di'] = $levels;
$this->differences['layout'] = $levels;
$this->differences['system'] = $levels;
$this->differences['xsd'] = $levels;
$this->differences['less'] = $levels;
foreach (static::$contexts as $context) {
$this->differences[$context] = $levels;
}
}
}
12 changes: 11 additions & 1 deletion src/ReportBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ protected function makeVersionReport()
return $report;
}

/**
* Get the mapping of report type -> analyzer factory
*
* @return array
*/
protected function getAnalyzerFactories()
{
return $this->analyzerList;
}

/**
* Create a report based on type
*
Expand Down Expand Up @@ -161,7 +171,7 @@ protected function buildReport()
/**
* @var AnalyzerFactoryInterface $factory
*/
foreach ($this->analyzerList as $reportType => $factory) {
foreach ($this->getAnalyzerFactories() as $reportType => $factory) {
/** @var AnalyzerInterface $analyzer */
$analyzer = (new $factory())->create($dependencyMap);
$tmpReport = $analyzer->analyze(
Expand Down
9 changes: 2 additions & 7 deletions src/Reporter/BreakingChangeTableReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// @codingStandardsIgnoreFile
namespace Magento\SemanticVersionChecker\Reporter;

use Magento\SemanticVersionChecker\DbSchemaReport;
use PHPSemVerChecker\Report\Report;
use PHPSemVerChecker\SemanticVersioning\Level;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -51,13 +52,7 @@ public function __construct($apiChangeReport, $apiMembershipReport, $targetFile)
*/
public function output(OutputInterface $output)
{
$contexts = [
'class',
'function',
'interface',
'trait',
'database',
];
$contexts = DbSchemaReport::$contexts;

foreach ($contexts as $context) {
$header = static::formatSectionHeader($this->targetFile, $context, 'breaking-change');
Expand Down