/** * @throws ReportException */ protected function throwInverseSideDefaultGetterMustReturnCollection() { $message = $this->getInverseSideClassName() . '::' . $this->getInverseSideGetter() . '()'; $message .= ' must return an instance of ' . Collection::class; $errorReport = new ErrorReport($message); $helpCollection = 'You should call $this->$' . $this->getInverseSideProperty(); $helpCollection .= ' = new ' . ArrayCollection::class . '() in '; $helpCollection .= $this->getInverseSideClassName() . '::__construct().'; $errorReport->addHelp($helpCollection); $helpReturn = $this->getInverseSideClassName() . '::' . $this->getInverseSideGetter() . '() should return '; $helpReturn .= $this->getInverseSideClassName() . '::$' . $this->getInverseSideProperty() . '.'; $errorReport->addHelp($helpReturn); $errorReport->addMethodCode($this->getInverseSideClassName(), '__construct'); $errorReport->addMethodCode($this->getInverseSideClassName(), $this->getInverseSideGetter()); throw new ReportException($this->getReport(), $errorReport); }
/** * @throws ReportException */ protected function inverseSideAdderThrowOwningSideEntityIdIsNull() { $message = $this->getOwningSideClassName() . '::' . $this->getOwningSideIdGetter() . '() return null '; $message .= 'after calling ' . $this->getInverseSideClassName() . '::' . $this->getInverseSideAdder() . '(), '; $message .= 'then ' . get_class($this->getManager()) . '::flush().'; $errorReport = new ErrorReport($message); $errorReport->addMethodCode($this->getOwningSideClassName(), $this->getOwningSideIdGetter()); $this->inverseSideAdderAddInverseSideEntityPersistError($errorReport); throw new ReportException($this->getReport(), $errorReport); }
/** * @throws ReportException */ protected function inverseSideSetterThrowDoesntSetProperty() { $message = $this->getInverseSideClassName() . '::' . $this->getInverseSideSetter() . '() doest not set '; $message .= $this->getInverseSideClassName() . '::$' . $this->getInverseSideProperty(); $errorReport = new ErrorReport($message); $help = 'This method should call $this->' . $this->getInverseSideClearer() . '(), '; $help .= $this->getInverseSideAdder() . '() for each ' . $this->getOwningSideClassName() . ' passed '; $help .= 'then ' . $this->getInverseSideProperty() . '->clear() to reset Collection keys.'; $errorReport->addHelp($help); $errorReport->addMethodCode($this->getInverseSideClassName(), $this->getInverseSideSetter()); throw new ReportException($this->getReport(), $errorReport); }
/** * @throws ReportException */ protected function throwRightEntityShouldNotBeManaged() { $message = '$this->owningSideEntity should not be managed, '; $message .= 'after calling ' . $this->leftEntityClass . '::' . $this->leftEntityRemover . '() '; $message .= 'and ' . $this->managerClass . '::flush().'; $errorReport = new ErrorReport($message); $errorReport->addMethodCode($this->leftEntity, $this->leftEntityRemover); throw new ReportException($this->getReport(), $errorReport); }
/** * @param string $className * @param string $method * @param array $parameters * @throws ReportException */ protected function throwMethodSignatureIsWrong($className, $method, array $parameters) { $message = $className . '::' . $method . '() signature is wrong.'; $errorReport = new ErrorReport($message); $help = $className . '::' . $method . '() must have at least this '; $help .= count($parameters) === 1 ? 'parameter: ' : 'parameters: '; $helpParameters = []; foreach ($parameters as $name => $types) { switch (count($types)) { case 0: $helpParameters[] = '$' . $name; break; case 1: $helpParameters[] = $types[0] . ' $' . $name; break; case 2: $helpParameters[] = $types[0] . ' $' . $name . ' = ' . $types[1]; break; } } $help .= implode(', ', $helpParameters) . '.'; $errorReport->addHelp($help); $errorReport->addMethodCode($className, $method); throw new ReportException($this->getReport(), $errorReport); }
/** * @return $this * @throws ReportException */ protected function validateOwningSideSetterPhpCode() { $template = __DIR__ . '/PhpTemplate/OwningSideSetter.tpl'; $inverseSideClass = substr($this->getInverseSideClassName(), strrpos($this->getInverseSideClassName(), '\\') + 1); $templateVars = ['setter' => $this->getOwningSideSetter(), 'parameters' => $inverseSideClass . ' $' . $this->getOwningSideProperty() . ' = null', 'parameter' => '$' . $this->getOwningSideProperty(), 'property' => $this->getOwningSideProperty()]; $isValid = $this->isPhpCodeEqualsToTemplate($this->getOwningSideClassName(), $this->getOwningSideSetter(), $template, $templateVars); if ($isValid === false) { $errorReport = new ErrorReport('Invalid PHP code for ' . $this->getOwningSideClassName() . '::' . $this->getOwningSideSetter() . '()'); $errorReport->addMethodCode($this->getOwningSideClassName(), $this->getOwningSideSetter()); $errorReport->addCode($template, explode("\n", $this->getPhpCodeFromTemplate($template, $templateVars))); throw new ReportException($this->getReport(), $errorReport); } return $this; }