/** * Will change code to create an entry for the old object state. * * @param string $bucketData Payload of the currently * filtered bucket * @param \AppserverIo\Doppelgaenger\Entities\Definitions\FunctionDefinition $functionDefinition Currently handled function * * @throws \AppserverIo\Doppelgaenger\Exceptions\GeneratorException * * @return boolean */ protected function injectOldCode(&$bucketData, FunctionDefinition &$functionDefinition) { // Do we even need to do anything? if ($functionDefinition->usesOld() !== true) { return false; } // If the function is static it should not use the dgOld keyword as there is no state to the class! if ($functionDefinition->isStatic() === true) { throw new GeneratorException(sprintf('Cannot clone class state in static method %s.', $functionDefinition->getName())); } // Still here? Then inject the clone statement to preserve an instance of the object prior to our call. $bucketData = str_replace(Placeholders::OLD_SETUP . $functionDefinition->getName() . Placeholders::PLACEHOLDER_CLOSE, ReservedKeywords::OLD . ' = clone $this;', $bucketData); // Still here? We encountered no error then. return true; }