Skip to content

Confusion in map() function. Needs clarification #122

@makoru-hikage

Description

@makoru-hikage

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions