dfuncd / repofuck

Fucking with the Repository Design Pattern
6 stars 2 forks source link

Confusion in map() function. Needs clarification #122

Open makoru-hikage opened 7 years ago

makoru-hikage commented 7 years ago

L481-493

if ( $this->hasValues($this->keys) ) {
            foreach($inserts as $key => $val)
            {
                if ( ! in_array($key, $inserts) ) {
                    continue;
                }
                $entity->{$key} = $val;
            }
            return $entity;
        }

Assume that $this->keys has a value: ['first_name', 'last_name']. The $inserts has this value:

[ 'username' => 'mlester', 'first_name' => 'Moe', 'last_name' => 'Lester' ].

So the in the first iteration shall be like this...

"If username is in ['mlester', 'Moe', 'Lester'] , continue."

What for?

Is this what was meant?

if ( $this->hasValues($this->keys) ) {
            foreach($inserts as $key => $val)
            {
                if ( ! in_array($key, $this->keys) ) {
                    continue;
                }
                $entity->{$key} = $val;
            }
            return $entity;
        }

If summarized, the snippet means that any element that has a key not found in $this->keys shall make the loop continue without going assigning a property-value pair ($entity->{$key} = $val;) to the $entity