| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace App\Blog\Post; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use App\Blog\Entity\Post; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use App\Service\WebControllerService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use App\User\UserService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Psr\Http\Message\ResponseInterface as Response; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Psr\Http\Message\ServerRequestInterface as Request; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Yiisoft\FormModel\FormHydrator; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Yiisoft\Http\Method; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Yiisoft\Router\CurrentRoute; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Yiisoft\Yii\View\Renderer\ViewRenderer; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | final class PostController | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         private WebControllerService $webService, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         private PostService $postService, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         private UserService $userService, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         private ViewRenderer $viewRenderer, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         $this->viewRenderer = $viewRenderer->withControllerName('blog/post'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     public function index(CurrentRoute $currentRoute, PostRepository $postRepository): Response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $canEdit = $this->userService->hasPermission('editPost'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         $slug = $currentRoute->getArgument('slug'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $item = $postRepository->fullPostPage($slug); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         if ($item === null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             return $this->webService->getNotFoundResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         return $this->viewRenderer->render('index', ['item' => $item, 'canEdit' => $canEdit, 'slug' => $slug]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |     public function add(Request $request, FormHydrator $formHydrator): Response | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |         $parameters = [ | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |             'title' => 'Add post', | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |             'action' => ['blog/add'], | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |             'errors' => [], | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |             'body' => $request->getParsedBody(), | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |         ]; | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |         if ($request->getMethod() === Method::POST) { | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |             $form = new PostForm(); | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |             if ($formHydrator->populateAndValidate($form, $parameters['body'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |                 $this->postService->savePost($this->userService->getUser(), new Post(), $form); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |                 return $this->webService->getRedirectResponse('blog/index'); | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |             $parameters['errors'] = $form->getValidationResult()->getErrorMessagesIndexedByProperty(); | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |         return $this->viewRenderer->render('__form', $parameters); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     public function edit( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         Request $request, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         PostRepository $postRepository, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         CurrentRoute $currentRoute, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         FormHydrator $formHydrator | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     ): Response { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         $slug = $currentRoute->getArgument('slug'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         $post = $postRepository->fullPostPage($slug); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         if ($post === null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             return $this->webService->getNotFoundResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         $parameters = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             'title' => 'Edit post', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             'action' => ['blog/edit', ['slug' => $slug]], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |             'errors' => [], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |             'body' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |                 'title' => $post->getTitle(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |                 'content' => $post->getContent(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |                 'tags' => $this->postService->getPostTags($post), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         if ($request->getMethod() === Method::POST) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             $form = new PostForm(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             $body = $request->getParsedBody(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |             if ($formHydrator->populateAndValidate($form, $body)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |                 $this->postService->savePost($this->userService->getUser(), $post, $form); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |                 return $this->webService->getRedirectResponse('blog/index'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |             $parameters['body'] = $body; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |             $parameters['errors'] = $form->getValidationResult()->getErrorMessagesIndexedByProperty(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         return $this->viewRenderer->render('__form', $parameters); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 100 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 101 |  |  |  | 
            
                        
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