/**
  * @param RelationshipsInterface $relationships
  * @return bool
  */
 protected function validateRequired(RelationshipsInterface $relationships)
 {
     $valid = true;
     foreach ($this->required as $key) {
         if (!$relationships->has($key)) {
             $this->addError($this->errorFactory->memberRequired($key, P::relationships()));
             $valid = false;
         }
     }
     return $valid;
 }
 /**
  * @param ResourceInterface $resource
  * @return bool
  */
 protected function validateId(ResourceInterface $resource)
 {
     /** If expecting an id, one must be provided */
     if (!is_null($this->expectedId) && !$resource->has(ResourceInterface::ID)) {
         $this->addError($this->errorFactory->memberRequired(ResourceInterface::ID, P::data()));
         return false;
     }
     /** If expecting an id, must match the one we're expecting */
     if (!is_null($this->expectedId) && $this->expectedId != $resource->getId()) {
         $this->addError($this->errorFactory->resourceUnsupportedId($this->expectedId, $resource->getId()));
         return false;
     }
     return true;
 }
 /**
  * @param ResourceIdentifierInterface $identifier
  * @param string|null $key
  * @return bool
  */
 protected function validateIdentifier(ResourceIdentifierInterface $identifier, $key = null)
 {
     $valid = true;
     /** Must have a type */
     if (!$identifier->hasType()) {
         $this->addError($this->errorFactory->memberRequired(ResourceIdentifierInterface::TYPE, $key ? P::relationshipData($key) : P::data()));
         $valid = false;
     } elseif (!$this->isSupportedType($identifier->getType())) {
         $this->addError($this->errorFactory->relationshipUnsupportedType($this->expectedTypes, $identifier->getType(), $key));
         $valid = false;
     }
     /** Must have an id */
     if (!$identifier->hasId()) {
         $this->addError($this->errorFactory->memberRequired(ResourceIdentifierInterface::ID, $key ? P::relationshipId($key) : P::data()));
         $valid = false;
     }
     return $valid;
 }