Esempio n. 1
0
 /**
  * Compare with a destination registry (what the new source code is like).
  *
  * @param \PHPSemVerChecker\Registry\Registry $registryBefore
  * @param \PHPSemVerChecker\Registry\Registry $registryAfter
  * @return \PHPSemVerChecker\Report\Report
  */
 public function analyze(Registry $registryBefore, Registry $registryAfter)
 {
     $finalReport = new Report();
     $analyzers = [new FunctionAnalyzer(), new ClassAnalyzer(), new InterfaceAnalyzer(), new TraitAnalyzer()];
     foreach ($analyzers as $analyzer) {
         $report = $analyzer->analyze($registryBefore, $registryAfter);
         $finalReport->merge($report);
     }
     return $finalReport;
 }
 public function analyze(Registry $registryBefore, Registry $registryAfter)
 {
     $report = new Report();
     $keysBefore = array_keys($registryBefore->data['trait']);
     $keysAfter = array_keys($registryAfter->data['trait']);
     $added = array_diff($keysAfter, $keysBefore);
     $removed = array_diff($keysBefore, $keysAfter);
     $toVerify = array_intersect($keysBefore, $keysAfter);
     foreach ($removed as $key) {
         $fileBefore = $registryBefore->mapping['trait'][$key];
         $traitBefore = $registryBefore->data['trait'][$key];
         $data = new TraitRemoved($fileBefore, $traitBefore);
         $report->addTrait($data);
     }
     foreach ($toVerify as $key) {
         $fileBefore = $registryBefore->mapping['trait'][$key];
         /** @var \PhpParser\Node\Stmt\Class_ $traitBefore */
         $traitBefore = $registryBefore->data['trait'][$key];
         $fileAfter = $registryAfter->mapping['trait'][$key];
         /** @var \PhpParser\Node\Stmt\Class_ $traitBefore */
         $traitAfter = $registryAfter->data['trait'][$key];
         // Leave non-strict comparison here
         if ($traitBefore != $traitAfter) {
             $analyzers = [new ClassMethodAnalyzer('trait', $fileBefore, $fileAfter), new PropertyAnalyzer('trait', $fileBefore, $fileAfter)];
             foreach ($analyzers as $analyzer) {
                 $internalReport = $analyzer->analyze($traitBefore, $traitAfter);
                 $report->merge($internalReport);
             }
         }
     }
     foreach ($added as $key) {
         $fileAfter = $registryAfter->mapping['trait'][$key];
         $traitAfter = $registryAfter->data['trait'][$key];
         $data = new TraitAdded($fileAfter, $traitAfter);
         $report->addTrait($data);
     }
     return $report;
 }
 public function analyze(Registry $registryBefore, Registry $registryAfter)
 {
     $report = new Report();
     $keysBefore = array_keys($registryBefore->data['interface']);
     $keysAfter = array_keys($registryAfter->data['interface']);
     $added = array_diff($keysAfter, $keysBefore);
     $removed = array_diff($keysBefore, $keysAfter);
     $toVerify = array_intersect($keysBefore, $keysAfter);
     foreach ($removed as $key) {
         $fileBefore = $registryBefore->mapping['interface'][$key];
         $interfaceBefore = $registryBefore->data['interface'][$key];
         $data = new InterfaceRemoved($fileBefore, $interfaceBefore);
         $report->addInterface($data);
     }
     foreach ($toVerify as $key) {
         $fileBefore = $registryBefore->mapping['interface'][$key];
         /** @var \PhpParser\Node\Stmt\Interface_ $interfaceBefore */
         $interfaceBefore = $registryBefore->data['interface'][$key];
         $fileAfter = $registryAfter->mapping['interface'][$key];
         /** @var \PhpParser\Node\Stmt\Interface_ $interfaceBefore */
         $interfaceAfter = $registryAfter->data['interface'][$key];
         // Leave non-strict comparison here
         if ($interfaceBefore != $interfaceAfter) {
             $analyzer = new ClassMethodAnalyzer('interface', $fileBefore, $fileAfter);
             $interfaceMethodReport = $analyzer->analyze($interfaceBefore, $interfaceAfter);
             $report->merge($interfaceMethodReport);
         }
     }
     foreach ($added as $key) {
         $fileAfter = $registryAfter->mapping['interface'][$key];
         $interfaceAfter = $registryAfter->data['interface'][$key];
         $data = new InterfaceAdded($fileAfter, $interfaceAfter);
         $report->addInterface($data);
     }
     return $report;
 }