public function assemble(ContextInterface $context)
    {
        $class = $context->getClass();
        $property = $context->getProperty();
        try {
            $methodName = Normalizer::generatePropertyMethod('with', $property->getName());
            $class->removeMethod($methodName);
            $lines = [
                sprintf('$new = clone $this;'),
                sprintf('$new->%1$s = $%1$s;', $property->getName()),
                '',
                sprintf('return $new;'),
            ];
            $parameterOptions = ['name' => $property->getName()];
            if ($this->options->useTypeHints()) {
                $parameterOptions['type'] = $property->getType();
            }
            $class->addMethodFromGenerator(
                MethodGenerator::fromArray(
                    [
                        'name' => $methodName,
                        'parameters' => [$parameterOptions],
                        'visibility' => MethodGenerator::VISIBILITY_PUBLIC,
                        'body' => implode($class::LINE_FEED, $lines),
                        'docblock' => DocBlockGeneratorFactory::fromArray([
                            'tags' => [
                                [
                                    'name' => 'param',
                                    'description' => sprintf('%s $%s', $property->getType(), $property->getName()),
                                ],
                                [
                                    'name' => 'return',
                                    'description' => $class->getName(),
                                ],
                            ],
                        ]),
                    ]
                )
            );
        } catch (\Exception $e) {
            throw AssemblerException::fromException($e);
        }
    }
public function assemble(ContextInterface $context)
    {
        $class = $context->getClass();
        $property = $context->getProperty();
        try {
            $methodName = Normalizer::generatePropertyMethod('with', $property->getName());
            $class->removeMethod($methodName);
            $lines = [
                sprintf('$new = clone $this;'),
                sprintf('$new->%1$s = $%1$s;', $property->getName()),
                '',
                sprintf('return $new;'),
            ];
            $parameterOptions = ['name' => $property->getName()];
            if ($this->options->useTypeHints()) {
                $parameterOptions['type'] = $property->getType();
            }
            $class->addMethodFromGenerator(
                MethodGenerator::fromArray(
                    [
                        'name' => $methodName,
                        'parameters' => [$parameterOptions],
                        'visibility' => MethodGenerator::VISIBILITY_PUBLIC,
                        'body' => implode($class::LINE_FEED, $lines),
                        'docblock' => DocBlockGeneratorFactory::fromArray([
                            'tags' => [
                                [
                                    'name' => 'param',
                                    'description' => sprintf('%s $%s', $property->getType(), $property->getName()),
                                ],
                                [
                                    'name' => 'return',
                                    'description' => $class->getName(),
                                ],
                            ],
                        ]),
                    ]
                )
            );
        } catch (\Exception $e) {
            throw AssemblerException::fromException($e);
        }
    }
public function assemble ( ContextInterface $ context ) { $ class = $ context -> getClass ( ) ; $ property = $ context -> getProperty ( ) ; try { $ methodName = Normalizer :: generatePropertyMethod ( 'with' , $ property -> getName ( ) ) ; $ class -> removeMethod ( $ methodName ) ; $ lines = [ sprintf ( '$new = clone $this;' ) , sprintf ( '$new->%1$s = $%1$s;' , $ property -> getName ( ) ) , '' , sprintf ( 'return $new;' ) , ] ; $ parameterOptions = [ 'name' => $ property -> getName ( ) ] ; if ( $ this -> options -> useTypeHints ( ) ) { $ parameterOptions [ 'type' ] = $ property -> getType ( ) ; } $ class -> addMethodFromGenerator ( MethodGenerator :: fromArray ( [ 'name' => $ methodName , 'parameters' => [ $ parameterOptions ] , 'visibility' => MethodGenerator :: VISIBILITY_PUBLIC , 'body' => implode ( $ class :: LINE_FEED , $ lines ) , 'docblock' => DocBlockGeneratorFactory :: fromArray ( [ 'tags' => [ [ 'name' => 'param' , 'description' => sprintf ( '%s $%s' , $ property -> getType ( ) , $ property -> getName ( ) ) , ] , [ 'name' => 'return' , 'description' => $ class -> getName ( ) , ] , ] , ] ) , ] ) ) ; } catch ( \ Exception $ e ) { throw AssemblerException :: fromException ( $ e ) ; } }
Assembles pieces of code.

@param ContextInterface|PropertyContext $context

@throws AssemblerException
Assembles pieces of code .