<?php
declare(strict_types=1);
namespace App\Services\Pipeline\Steps;
use App\Core\Database; use App\Services\Pipeline\AbstractPipelineStep;
final class DependencyPipelineStep extends AbstractPipelineStep {
 public function code():string{return 'dependencies';} public function label():string{return 'Dépendances';} public function order():int{return 50;}
 public function execute(array $c):array {$issues=[];$warnings=[];foreach((array)($c['manifest']['dependencies']??[]) as $dep){$name=trim((string)($dep['package_id']??''));$min=trim((string)($dep['min_version']??'0.0.0'));$max=trim((string)($dep['max_version']??''));if($name===''){$issues[]='Dépendance sans identifiant.';continue;}$s=Database::connection()->prepare("SELECT version_package FROM cda_update_packages WHERE nom_package=:package AND statut IN ('installe','installed') ORDER BY id DESC LIMIT 1");$s->execute(['package'=>$name]);$v=$s->fetchColumn();if(!is_string($v)){$issues[]='Dépendance absente : '.$name.'.';continue;}if(version_compare($v,$min,'<'))$issues[]='Dépendance trop ancienne : '.$name.' '.$v.'.';if($max!==''&&version_compare($v,$max,'>'))$issues[]='Dépendance trop récente : '.$name.' '.$v.'.';}if(empty($c['manifest']['dependencies']))$warnings[]='Aucune dépendance déclarée.';return $this->result($issues?'BLOCKED':($warnings?'WARNING':'RESOLVED'),$issues?0:100,$issues?'Dépendances non résolues.':'Dépendances analysées.',$issues,$warnings,[],(bool)$issues);}
}
