Phpro\SoapClient\CodeGenerator\Assembler\FluentSetterAssembler::assemble PHP Method

assemble() public method

public assemble ( Phpro\SoapClient\CodeGenerator\Context\ContextInterface $context )
$context Phpro\SoapClient\CodeGenerator\Context\ContextInterface
    public function assemble(ContextInterface $context)
    {
        $class = $context->getClass();
        $property = $context->getProperty();
        try {
            $methodName = Normalizer::generatePropertyMethod('set', $property->getName());
            $class->removeMethod($methodName);
            $class->addMethodFromGenerator(MethodGenerator::fromArray(['name' => $methodName, 'parameters' => [$property->getName()], 'visibility' => MethodGenerator::VISIBILITY_PUBLIC, 'body' => sprintf('$this->%1$s = $%1$s;%2$sreturn $this;', $property->getName(), $class::LINE_FEED), 'docblock' => DocBlockGenerator::fromArray(['tags' => [['name' => 'param', 'description' => sprintf('%s $%s', $property->getType(), $property->getName())], ['name' => 'return', 'description' => '$this']]])]));
        } catch (\Exception $e) {
            throw AssemblerException::fromException($e);
        }
    }

Usage Example

    /**
     * @test
     */
    function it_assembles_a_property()
    {
        $assembler = new FluentSetterAssembler();
        $context = $this->createContext();
        $assembler->assemble($context);
        $code = $context->getClass()->generate();
        $expected = <<<CODE
namespace MyNamespace;

class MyType
{

    /**
     * @param string \$prop1
     * @return \$this
     */
    public function setProp1(\$prop1)
    {
        \$this->prop1 = \$prop1;
        return \$this;
    }


}

CODE;
        $this->assertEquals($expected, $code);
    }
FluentSetterAssembler