| 1 |  |  | <?php declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of the pinepain/js-sandbox PHP library. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * Copyright (c) 2016-2017 Bogdan Padalko <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * Licensed under the MIT license: http://opensource.org/licenses/MIT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * For the full copyright and license information, please view the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * LICENSE file that was distributed with this source or visit | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * http://opensource.org/licenses/MIT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | namespace Pinepain\JsSandbox\Extractors\PlainExtractors; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Pinepain\JsSandbox\Extractors\Definition\PlainExtractorDefinitionInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use Pinepain\JsSandbox\Extractors\ExtractorException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use Pinepain\JsSandbox\Extractors\ExtractorInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use Pinepain\JsSandbox\Extractors\ObjectComponents\ExtractorsObjectStoreInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use UnexpectedValueException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | use V8\Context; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | use V8\ObjectValue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | use V8\Value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | class NativeObjectExtractor implements PlainExtractorInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * @var ExtractorsObjectStoreInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     private $object_store; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 36 | 6 |  |     public function __construct(ExtractorsObjectStoreInterface $object_store) | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 38 | 6 |  |         $this->object_store = $object_store; | 
            
                                                                        
                            
            
                                    
            
            
                | 39 | 6 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 6 |  |     public function extract(Context $context, Value $value, PlainExtractorDefinitionInterface $definition, ExtractorInterface $extractor) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 6 |  |         if ($value instanceof ObjectValue) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 | 5 |  |                 $instance = $this->object_store->get($value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 4 |  |                 if ($definition->getNext()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 3 |  |                     foreach ($definition->getNext()->getVariations() as $variation) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 2 |  |                         if (is_a($instance, $variation->getName())) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 2 |  |                             return $instance; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |                         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 2 |  |                     throw new ExtractorException('Native object value constraint failed: value is not an instance of given classes/interfaces'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 1 |  |                 return $instance; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 | 3 |  |             } catch (UnexpectedValueException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 1 |  |                 throw new ExtractorException('Unable to find bound native object'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 1 |  |         throw new ExtractorException('Value must be of the type object to be able to find instance, ' . $value->typeOf()->value() . ' given'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 68 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 69 |  |  |  | 
            
                        
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.