| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of the Superdesk Web Publisher Core Bundle. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * Copyright 2016 Sourcefabric z.u. and contributors. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * For the full copyright and license information, please see the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * AUTHORS and LICENSE files distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @copyright 2016 Sourcefabric z.ú | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @license http://www.superdesk.org/license | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | namespace SWP\Bundle\CoreBundle\Theme\Loader; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Sylius\Bundle\ThemeBundle\Configuration\ConfigurationProviderInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Sylius\Bundle\ThemeBundle\Factory\ThemeAuthorFactoryInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Sylius\Bundle\ThemeBundle\Factory\ThemeFactoryInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use Sylius\Bundle\ThemeBundle\Factory\ThemeScreenshotFactoryInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use Sylius\Bundle\ThemeBundle\Loader\CircularDependencyCheckerInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use Sylius\Bundle\ThemeBundle\Loader\CircularDependencyFoundException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use Sylius\Bundle\ThemeBundle\Loader\ThemeLoaderInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | use Sylius\Bundle\ThemeBundle\Loader\ThemeLoadingFailedException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | use Sylius\Bundle\ThemeBundle\Model\ThemeAuthor; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | use Sylius\Bundle\ThemeBundle\Model\ThemeInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | use Sylius\Bundle\ThemeBundle\Model\ThemeScreenshot; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  * @author Kamil Kokot <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  * @author Paweł Mikołajczuk <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | final class TenantAwareThemeLoader implements ThemeLoaderInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * @var ConfigurationProviderInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     private $configurationProvider; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @var ThemeFactoryInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     private $themeFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      * @var ThemeAuthorFactoryInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     private $themeAuthorFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * @var ThemeScreenshotFactoryInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     private $themeScreenshotFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * @var CircularDependencyCheckerInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     private $circularDependencyChecker; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * @param ConfigurationProviderInterface     $configurationProvider | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * @param ThemeFactoryInterface              $themeFactory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * @param ThemeAuthorFactoryInterface        $themeAuthorFactory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * @param ThemeScreenshotFactoryInterface    $themeScreenshotFactory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * @param CircularDependencyCheckerInterface $circularDependencyChecker | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         ConfigurationProviderInterface $configurationProvider, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         ThemeFactoryInterface $themeFactory, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         ThemeAuthorFactoryInterface $themeAuthorFactory, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         ThemeScreenshotFactoryInterface $themeScreenshotFactory, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         CircularDependencyCheckerInterface $circularDependencyChecker | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $this->configurationProvider = $configurationProvider; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         $this->themeFactory = $themeFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         $this->themeAuthorFactory = $themeAuthorFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         $this->themeScreenshotFactory = $themeScreenshotFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $this->circularDependencyChecker = $circularDependencyChecker; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     public function load(): array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         $configurations = $this->configurationProvider->getConfigurations(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         $themes = $this->initializeThemes($configurations); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         $themes = $this->hydrateThemes($configurations, $themes); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         $this->checkForCircularDependencies($themes); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         return array_values($themes); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      * @param array $configurations | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      * @return ThemeInterface[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     private function initializeThemes(array $configurations) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         $themes = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         foreach ($configurations as $configuration) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |             /* @var ThemeInterface $theme */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |             $themes[$configuration['name']] = $this->themeFactory->create($configuration['name'], $configuration['path']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         return $themes; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |      * @param array            $configurations | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |      * @param ThemeInterface[] $themes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |      * @return ThemeInterface[] | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 117 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  |     private function hydrateThemes(array $configurations, array $themes) | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  |         foreach ($configurations as $configuration) { | 
            
                                                                        
                            
            
                                    
            
            
                | 121 |  |  |             $themeName = $configuration['name']; | 
            
                                                                        
                            
            
                                    
            
            
                | 122 |  |  |             $configuration['parents'] = $this->convertParentsNamesToParentsObjects($themeName, $configuration['parents'], $themes); | 
            
                                                                        
                            
            
                                    
            
            
                | 123 |  |  |             $configuration['authors'] = $this->convertAuthorsArraysToAuthorsObjects($configuration['authors']); | 
            
                                                                        
                            
            
                                    
            
            
                | 124 |  |  |             $configuration['screenshots'] = $this->convertScreenshotsArraysToScreenshotsObjects($configuration['screenshots']); | 
            
                                                                        
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 126 |  |  |             $theme = $themes[$configuration['name']]; | 
            
                                                                        
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 128 |  |  |             $theme->setTitle($configuration['title'] ?? null); | 
            
                                                                        
                            
            
                                    
            
            
                | 129 |  |  |             $theme->setDescription($configuration['description'] ?? null); | 
            
                                                                        
                            
            
                                    
            
            
                | 130 |  |  |             $theme->setName($configuration['name']); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 131 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 132 |  |  |             //$parentThemes = $this->convertParentsNamesToParentsObjects($configuration['name'], $configuration['parents'], $themes); | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  |             foreach ($configuration['parents'] as $parentTheme) { | 
            
                                                                        
                            
            
                                    
            
            
                | 134 |  |  |                 $theme->addParent($parentTheme); | 
            
                                                                        
                            
            
                                    
            
            
                | 135 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 136 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 137 |  |  |             //$themeAuthors = $this->convertAuthorsArraysToAuthorsObjects($configuration['authors']); | 
            
                                                                        
                            
            
                                    
            
            
                | 138 |  |  |             foreach ($configuration['authors'] as $themeAuthor) { | 
            
                                                                        
                            
            
                                    
            
            
                | 139 |  |  |                 $theme->addAuthor($themeAuthor); | 
            
                                                                        
                            
            
                                    
            
            
                | 140 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 141 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 142 |  |  |             //$themeScreenshots = $this->convertScreenshotsArraysToScreenshotsObjects($configuration['screenshots']); | 
            
                                                                        
                            
            
                                    
            
            
                | 143 |  |  |             foreach ($configuration['screenshots'] as $themeScreenshot) { | 
            
                                                                        
                            
            
                                    
            
            
                | 144 |  |  |                 $theme->addScreenshot($themeScreenshot); | 
            
                                                                        
                            
            
                                    
            
            
                | 145 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 146 |  |  |             $themes[$themeName] = $theme; | 
            
                                                                        
                            
            
                                    
            
            
                | 147 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 148 |  |  |             if(isset($configuration['generatedData'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 149 |  |  |                 $theme->setGeneratedData($configuration['generatedData']); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 150 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 151 |  |  |             //$themes[$themeName] = $this->themeHydrator->hydrate($configuration, $themes[$themeName]); | 
            
                                                                        
                            
            
                                    
            
            
                | 152 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 153 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 154 |  |  |         return $themes; | 
            
                                                                        
                            
            
                                    
            
            
                | 155 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |      * @param ThemeInterface[] $themes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |     private function checkForCircularDependencies(array $themes) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |             foreach ($themes as $theme) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |                 $this->circularDependencyChecker->check($theme); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |         } catch (CircularDependencyFoundException $exception) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |             throw new ThemeLoadingFailedException('Circular dependency found.', 0, $exception); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |      * @param string $themeName | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |      * @param array  $parentsNames | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |      * @param array  $existingThemes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |      * @return ThemeInterface[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |     private function convertParentsNamesToParentsObjects($themeName, array $parentsNames, array $existingThemes) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |         $tenantCode = substr($themeName, strpos($themeName, '@') + 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |         return array_map(function ($parentName) use ($themeName, $existingThemes, $tenantCode) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |             $parentName .= '@'.$tenantCode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |             if (!isset($existingThemes[$parentName])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |                 throw new ThemeLoadingFailedException(sprintf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |                     'Unexisting theme "%s" is required by "%s".', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |                     $parentName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |                     $themeName | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |                 )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |             return $existingThemes[$parentName]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |         }, $parentsNames); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |      * @param array $authorsArrays | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |      * @return ThemeAuthor[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |     private function convertAuthorsArraysToAuthorsObjects(array $authorsArrays) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |         return array_map(function (array $authorArray) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |             return $this->themeAuthorFactory->createFromArray($authorArray); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |         }, $authorsArrays); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |      * @param array $screenshotsArrays | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |      * @return ThemeScreenshot[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |     private function convertScreenshotsArraysToScreenshotsObjects(array $screenshotsArrays) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |         return array_map(function (array $screenshotArray) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |             return $this->themeScreenshotFactory->createFromArray($screenshotArray); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |         }, $screenshotsArrays); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 219 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 220 |  |  |  | 
            
                        
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: