| 1 |  |  | <?php namespace Anomaly\Streams\Platform\Ui\Form\Component\Field; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | use Anomaly\Streams\Platform\Ui\Form\FormBuilder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * Class FieldFiller | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @link   http://pyrocms.com/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @author PyroCMS, Inc. <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @author Ryan Thompson <[email protected]> | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 11 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  | class FieldFiller | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |      * Fill in fields. | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |      * @param FormBuilder $builder | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     public function fill(FormBuilder $builder) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         $fields = $builder->getFields(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         $stream = $builder->getFormStream(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |          * If no Stream, skip it. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         if (!$stream) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |             if (array_search('*', $fields) !== false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |                 unset($fields[array_search('*', $fields)]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |                 $builder->setFields($fields); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |          * Fill with everything by default. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $fill = $stream->getAssignments()->fieldSlugs(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |          * Loop over field configurations and unset | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |          * them from the fill fields. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |          * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |          * If we come across the fill marker then | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |          * set the position. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         foreach ($fields as $parameters) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             if (is_string($parameters) && $parameters === '*') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                 continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |              * If we found a field then | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |              * unset it from the fill fields. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |              */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             if (($search = array_search($parameters['field'], $fill)) !== false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |                 unset($fill[$search]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |          * If we have a fill marker then splice | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |          * in the remaining fill fields in place | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |          * of the fill marker. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         if (($position = array_search('*', $fields)) !== false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             array_splice($fields, $position, null, $fill); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             unset($fields[array_search('*', $fields)]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         $builder->setFields($fields); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 76 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 77 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 78 |  |  |  | 
            
                        
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.