| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace SavinMikhail\CommentsDensity; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Doctrine\DBAL\Connection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Doctrine\DBAL\Exception; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use SavinMikhail\CommentsDensity\Database\SQLiteDatabaseManager; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use SavinMikhail\CommentsDensity\DTO\Output\OutputDTO; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use function file_exists; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use function touch; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | final class BaselineManager | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     private static ?self $instance = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     private Connection $connection; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |     private function __construct() | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |         $this->init(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     public static function getInstance(): self | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         if (self::$instance === null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |             self::$instance = new self(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         return self::$instance; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     private function init(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $databaseFile = __DIR__ . '/../../comments_density.sqlite'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         if (!file_exists($databaseFile)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             touch($databaseFile); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $dbManager = new SQLiteDatabaseManager($databaseFile); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $this->connection = $dbManager->getConnection(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      * @throws Exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     public function set(OutputDTO $outputDTO): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         foreach ($outputDTO->comments as $comment) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |                 $this->connection->insert('comments', [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |                     'file_path' => $comment->file, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                     'line_number' => $comment->line, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |                     'comment' => $comment->content, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |                     'type' => $comment->commentType, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |                 ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             } catch (Exception $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |                 if ($this->isUniqueConstraintViolation($e)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |                     $this->connection->update('comments', [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |                         'comment' => $comment->content, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |                         'type' => $comment->commentType, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |                     ], [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |                         'file_path' => $comment->file, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |                         'line_number' => $comment->line, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |                     ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |                     continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |                 throw $e; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     private function isUniqueConstraintViolation(Exception $e): bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         return str_contains($e->getMessage(), 'UNIQUE constraint failed'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     public function getAllComments(): array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         $query = $this->connection->createQueryBuilder() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             ->select('*') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             ->from('comments') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |             ->executeQuery(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         return $query->fetchAllAssociative(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 86 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 87 |  |  |  | 
            
                        
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths