mpociot / laravel-test-factory-helper

Generate Laravel test factories from your existing models
935 stars 87 forks source link

Update GenerateCommand.php #31

Closed uonick closed 5 years ago

uonick commented 5 years ago

array → [] return types added some syntax fixes

😟

uonick commented 5 years ago

and.. use Laravel stubs for more customizable class content and clean code:

uonick commented 5 years ago

Something like that:

    /**
     * Return file template
     */
    public function getTemplate(): string
    {
        return str_replace(
            [
                '${class}',
            ],
            [
                $this->getInterfaceName(),
            ],
            $this->getStubContents()
        );
    }

    /**
     * Return interface name
     */
    private function getInterfaceName(): string
    {
        return sprintf(
            '%sRepositoryInterface',
            $this->getClassName()
        );
    }
    public function getTemplate(): string
    {
        return str_replace(
            [
                '${namespace}',
                '${extends}',
                '${extends_class}',
                '${class}',
                '${constants}',
                '${getters}',
            ],
            [
                $this->getNamespace(),
                $this->getExtends(),
                $this->getExtendsClass(),
                $this->getClassName(),
                $this->getColumns(),
                $this->getGetterMethods(),
            ],
            $this->getStubContents()
        );
    }
protected function getStubContents(): string
    {
        return file_get_contents(
            sprintf(
                '%s/%s.stub',
                config('generator.stubs'),
                $this->getType()
            )
        );
    }
jasonmccreary commented 5 years ago

This looks pretty good. But are you sure that all the of these added return types are supported in PHP 7.0? That's the current supported version in order to remain compatible with Laravel 5.5.

uonick commented 5 years ago

Yeah. Return types appear in PHP 7.0

jasonmccreary commented 5 years ago

Sure. But not all of them. It wasn't until 7.1 void and nullable types were supported.

Unfortunately we need to maintain compatibility with 7.0 in order to support the latest Laravel LTS version (5.5).

Feel free to break these up into smaller PRs and we can get the other stuff through, or remove the incompatibilities. 👍