original_string: public static function mergeEntities($targetEntity, $mergeEntity)
      {
          $reflect = new \ReflectionClass($mergeEntity);
          $properties = $reflect->getProperties(\ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED);
  
          foreach ($properties as $property) {
  
              if (!method_exists($mergeEntity, 'get' . ucfirst($property->getName()))) {
                  continue;
              }
  
              $value = $mergeEntity->{'get' . ucfirst($property->getName())}();
  
              if (is_a($value, '\\TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage')) {
                  $targetEntity->{'set' . ucfirst($property->getName())}(new ObjectStorage());
                  $singular = (preg_match('~s$~i', $property->getName()) > 0)
                      ? rtrim($property->getName(), 's')
                      : sprintf('%ss', $property->getName());
                  foreach ($value->toArray() as $item) {
                      $targetEntity->{'add' . ucfirst($singular)}($item);
                  }
              } elseif (!empty(trim($value))) {
                  $targetEntity->{'set' . ucfirst($property->getName())}($value);
              }
          }
  
          return $targetEntity;
      }
code: public static function mergeEntities($targetEntity, $mergeEntity)
      {
          $reflect = new \ReflectionClass($mergeEntity);
          $properties = $reflect->getProperties(\ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED);
  
          foreach ($properties as $property) {
  
              if (!method_exists($mergeEntity, 'get' . ucfirst($property->getName()))) {
                  continue;
              }
  
              $value = $mergeEntity->{'get' . ucfirst($property->getName())}();
  
              if (is_a($value, '\\TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage')) {
                  $targetEntity->{'set' . ucfirst($property->getName())}(new ObjectStorage());
                  $singular = (preg_match('~s$~i', $property->getName()) > 0)
                      ? rtrim($property->getName(), 's')
                      : sprintf('%ss', $property->getName());
                  foreach ($value->toArray() as $item) {
                      $targetEntity->{'add' . ucfirst($singular)}($item);
                  }
              } elseif (!empty(trim($value))) {
                  $targetEntity->{'set' . ucfirst($property->getName())}($value);
              }
          }
  
          return $targetEntity;
      }
code_tokens: public static function mergeEntities ( $ targetEntity , $ mergeEntity ) { $ reflect = new \ ReflectionClass ( $ mergeEntity ) ; $ properties = $ reflect -> getProperties ( \ ReflectionProperty :: IS_PUBLIC | \ ReflectionProperty :: IS_PROTECTED ) ; foreach ( $ properties as $ property ) { if ( ! method_exists ( $ mergeEntity , 'get' . ucfirst ( $ property -> getName ( ) ) ) ) { continue ; } $ value = $ mergeEntity -> { 'get' . ucfirst ( $ property -> getName ( ) ) } ( ) ; if ( is_a ( $ value , '\\TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage' ) ) { $ targetEntity -> { 'set' . ucfirst ( $ property -> getName ( ) ) } ( new ObjectStorage ( ) ) ; $ singular = ( preg_match ( '~s$~i' , $ property -> getName ( ) ) > 0 ) ? rtrim ( $ property -> getName ( ) , 's' ) : sprintf ( '%ss' , $ property -> getName ( ) ) ; foreach ( $ value -> toArray ( ) as $ item ) { $ targetEntity -> { 'add' . ucfirst ( $ singular ) } ( $ item ) ; } } elseif ( ! empty ( trim ( $ value ) ) ) { $ targetEntity -> { 'set' . ucfirst ( $ property -> getName ( ) ) } ( $ value ) ; } } return $ targetEntity ; }
docstring: Merges two equal entities into the target entity
  
  @param $targetEntity
  @param $mergeEntity
  @return mixed
docstring_tokens: Merges two equal entities into the target entity