New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add static-based return type #880

Merged
merged 1 commit into from Dec 22, 2018

Conversation

1 participant
@TomasVotruba
Copy link
Member

TomasVotruba commented Dec 21, 2018

Closes #840

1. Simple

-   function getItems()
+   function getItems(): array
    {
        return [];
    }

-   function getMoreItems()
+   function getMoreItems(): array
    {
        if (true) {
            return [];
        }

        return [];
    }

    function getMoreWhatever()
    {
        if (true) {
            return false;
        }

        return [];
    }
}

2. Advanced

-   function getMoreWhatever()
+   function getMoreWhatever(): ?array
    {
        if (true) {
            return null;
        }

        return [];
    }

3. Code over Docs

    /**
     * @return int
     */
-   function getMoreWhatever()
+   function getMoreWhatever(): string
    {
        return 'hi';
    }

4. Objects

 class KnownStaticObject
 {
-    public function getObject()
+    public function getObject(): \stdClass
     {
         $object = new \stdClass;
         return $object;
     }

-    public function getTiny()
+    public function getTiny(): \Tiny
     {
         $object = new Tiny();
         return $object;
     }

-    public function getMaybe($value)
+    public function getMaybe($value): ?\Tiny
     {
         $object = null;
         if ($value) {
             $object = new \stdClass;
         }
         return $object;
     }
 }

@TomasVotruba TomasVotruba changed the title [WIP] Add static-based return and param types [WIP] Add static-based return types Dec 21, 2018

@TomasVotruba TomasVotruba force-pushed the types-known branch 2 times, most recently from f254252 to 1f3adfc Dec 21, 2018

@TomasVotruba TomasVotruba changed the title [WIP] Add static-based return types Add static-based return types Dec 21, 2018

@TomasVotruba TomasVotruba changed the title Add static-based return types Add static-based return type Dec 21, 2018

@TomasVotruba TomasVotruba force-pushed the types-known branch from 1f3adfc to 9ac65b0 Dec 21, 2018

@TomasVotruba TomasVotruba force-pushed the types-known branch from 30cc9c1 to 9631449 Dec 22, 2018

@TomasVotruba TomasVotruba merged commit 447f298 into master Dec 22, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@TomasVotruba TomasVotruba deleted the types-known branch Dec 22, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment