Skip to content
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/vendor
/.idea
auth.json
1 change: 1 addition & 0 deletions src/Analyzer/Analyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function analyze($registryBefore, $registryAfter)
$analyzers = [
new ClassAnalyzer(),
new InterfaceAnalyzer(),
// @todo should moved in a extra analyzer for a better extendability.
Copy link
Member

@melnikovi melnikovi Aug 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We try to avoid adding @todo annotation in the code. Let's add items like this to backlog and remove annotation in the code.

new DbSchemaAnalyzer(),
new DbSchemaWhitelistAnalyzer(),
new DbSchemaWhitelistReductionAnalyzer()
Expand Down
79 changes: 34 additions & 45 deletions src/BreakingChangeDocReportBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

namespace Magento\SemanticVersionChecker;

use Exception;
use Magento\SemanticVersionChecker\Analyzer\ApiMembership\ApiMembershipAnalyzer;
use Magento\SemanticVersionChecker\Finder\DbSchemaFinderDecorator;
use Magento\SemanticVersionChecker\Scanner\DbSchemaScannerDecorator;
use PHPSemVerChecker\Report\Report;

class BreakingChangeDocReportBuilder extends ReportBuilder
Expand All @@ -28,78 +28,67 @@ class BreakingChangeDocReportBuilder extends ReportBuilder
*/
public function makeCompleteVersionReport()
{
$this->makeVersionReport(static::REPORT_TYPE_API);
$this->makeVersionReport();
}

/**
* Create BIC reports for API changes and existing code that gained or lost API membership
* Get the report of changes made to the existing APIs
*
* @return Report
*/
public function getBreakingChangeReport()
{
return $this->changeReport;
}

/**
* Get the report of changes made to API membership (items that gained/lost API status)
*
* @param string $ignoredReportType
* @return Report
*/
public function getApiMembershipReport()
{
return $this->membershipReport;
}

/**
* Create BIC reports for API changes and existing code that gained or lost API membership
* @return void
* @throws \Exception
* @throws Exception
*/
protected function buildReport($ignoredReportType = null)
protected function buildReport()
{
$fileIterator = new DbSchemaFinderDecorator();
$sourceBeforeFiles = $fileIterator->findFromString($this->sourceBeforeDir, '', '');
$sourceAfterFiles = $fileIterator->findFromString($this->sourceAfterDir, '', '');

$apiScannerBefore = new DbSchemaScannerDecorator(static::REPORT_TYPE_API);
$apiScannerAfter = new DbSchemaScannerDecorator(static::REPORT_TYPE_API);

$fullScannerBefore = new DbSchemaScannerDecorator(static::REPORT_TYPE_ALL);
$fullScannerAfter = new DbSchemaScannerDecorator(static::REPORT_TYPE_ALL);
$scannerRegistryBefore = new ScannerRegistry($this->objectContainer->getAllScanner());
$scannerRegistryAfter = new ScannerRegistry($this->objectContainer->getAllScanner());

$filters = $this->getFilters($this->sourceBeforeDir, $this->sourceAfterDir);
foreach ($filters as $filter) {
$filter->filter($sourceBeforeFiles, $sourceAfterFiles);
}

foreach ($sourceBeforeFiles as $file) {
$fullScannerBefore->scan($file);
$apiScannerBefore->scan($file);
$scannerRegistryBefore->scanFile($file);
}

foreach ($sourceAfterFiles as $file) {
$fullScannerAfter->scan($file);
$apiScannerAfter->scan($file);
$scannerRegistryAfter->scanFile($file);
}

$apiRegistryBefore = $apiScannerBefore->getRegistry();
$apiRegistryAfter = $apiScannerAfter->getRegistry();

$fullRegistryBefore = $fullScannerBefore->getRegistry();
$fullRegistryAfter = $fullScannerAfter->getRegistry();
$beforeRegistryList = $scannerRegistryBefore->getScannerRegistryList();
$afterRegistryList = $scannerRegistryAfter->getScannerRegistryList();

$analyzer = new ApiMembershipAnalyzer();
$analyzer->analyzeWithMembership(
$apiRegistryBefore,
$apiRegistryAfter,
$fullRegistryBefore,
$fullRegistryAfter
$beforeRegistryList[self::REPORT_TYPE_API],
$afterRegistryList[self::REPORT_TYPE_API],
$beforeRegistryList[self::REPORT_TYPE_ALL],
$afterRegistryList[self::REPORT_TYPE_ALL]
);

$this->changeReport = $analyzer->getBreakingChangeReport();
$this->membershipReport = $analyzer->getApiMembershipReport();
}

/**
* Get the report of changes made to the existing APIs
*
* @return Report
*/
public function getBreakingChangeReport()
{
return $this->changeReport;
}

/**
* Get the report of changes made to API membership (items that gained/lost API status)
*
* @return Report
*/
public function getApiMembershipReport()
{
return $this->membershipReport;
}
}
102 changes: 102 additions & 0 deletions src/ObjectBuilderContainer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to make sure all files have Magento copyright. Dod you mention tests are green on this PR? If so need to double check if they run.



namespace Magento\SemanticVersionChecker;


use Magento\SemanticVersionChecker\Scanner\DbSchemaScannerDecorator;
use Magento\SemanticVersionChecker\Scanner\Scanner;
use Magento\SemanticVersionChecker\Visitor\ApiClassVisitor;
use Magento\SemanticVersionChecker\Visitor\ApiInterfaceVisitor;
use PhpParser\Lexer\Emulative;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor\NameResolver;
use PhpParser\Parser\Php7 as Parser;
use PHPSemVerChecker\Registry\Registry;
use PHPSemVerChecker\Visitor\ClassVisitor;
use PHPSemVerChecker\Visitor\FunctionVisitor;
use PHPSemVerChecker\Visitor\InterfaceVisitor;
use PHPSemVerChecker\Visitor\TraitVisitor;

class ObjectBuilderContainer
{

public function getAllScanner(): array
{
// @todo use dependency injection
$scanner = $this->buildFullScanner();
$scannerApi = $this->buildApiScanner();
// @todo refactoring should use own registry step 1 to get an working poc
$scannerDb = new DbSchemaScannerDecorator($scanner->getRegistry());

return [
'all' => [
'type' => 'php',
'pattern' => [
'*.php',
],
'scanner' => $scanner,
],
'api' => [
'type' => 'php',
'pattern' => [
'*.php',
],
'scanner' => $scannerApi,
],
'dbSchema' => [
'type' => 'xml',
'pattern' => [
'*.xml',
],
'scanner' => $scannerDb,
],
];
}

/**
* @return Scanner
* @todo use dependency injection
*/
private function buildFullScanner()
{
$registry = new Registry();
$parser = new Parser(new Emulative());
$traverser = new NodeTraverser();

$classVisitor = new ClassVisitor($registry);
$interfaceVisitor = new InterfaceVisitor($registry);
$apiVisitors = [
new NameResolver(),
$classVisitor,
$interfaceVisitor,
new FunctionVisitor($registry),
new TraitVisitor($registry),
];

return new Scanner($registry, $parser, $traverser, $apiVisitors);
}

/**
* @return Scanner
* @todo use dependency injection
*/
private function buildApiScanner()
{
$registry = new Registry();
$parser = new Parser(new Emulative());
$traverser = new NodeTraverser();

$classVisitor = new ApiClassVisitor($registry);
$interfaceVisitor = new ApiInterfaceVisitor($registry);
$apiVisitors = [
new NameResolver(),
$classVisitor,
$interfaceVisitor,
new FunctionVisitor($registry),
new TraitVisitor($registry),
];

return new Scanner($registry, $parser, $traverser, $apiVisitors);
}
}
Loading