Skip to content
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

Native types being assigned to current namespace #3

Open
jdrydn opened this issue Dec 31, 2017 · 9 comments
Open

Native types being assigned to current namespace #3

jdrydn opened this issue Dec 31, 2017 · 9 comments

Comments

@jdrydn
Copy link

jdrydn commented Dec 31, 2017

When generating documentation for a class under a namespace, certain types seem to be mapped to the namespace instead of remaining their native PHP types.

For instance,

namespace My\Awesome\Library;

class Person {
    public function waveTo(string $name, array $opts = []) {
        return "Waved to $name";
    }
}

Produces documentation looking like:

### waveTo

``php
Person::waveTo( \My\Awesome\Library\string $key,  array $opts = [] ): string
``

**Parameters:**

| Parameter | Type | Description |
|-----------|------|-------------|
| `$name` | **\My\Awesome\Library\string** |  |
| `$opts` | **array** |  |

When obviously this is a native string identifier, and adding \string to the function causes PHP to throw a syntax error. What I don't understand is where this template is excluding array, otherwise I'd just add string to the list of native classes to ignore!

Any ideas where this can be done? It's a pretty perfect template otherwise!

@jdrydn
Copy link
Author

jdrydn commented Dec 31, 2017

http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration

I'm aware string type declaration support was only added in PHP 7, wondering if this is a PHPDoc issue more than this template! 🤦‍♂️

@cvuorinen
Copy link
Owner

This template gets the type info from phpDocumentor. What version of phpDocumentor do you have installed? Seems like PHP 7 support was added in version 2.9 https://github.com/phpDocumentor/phpDocumentor2/releases

@jdrydn
Copy link
Author

jdrydn commented Jan 1, 2018

Yeah, I think I had installed v2.9 beforehand, but reverted to 2.8 after seeing this message:

Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for cvuorinen/phpdoc-markdown-public ^0.1.2 -> satisfiable by cvuorinen/phpdoc-markdown-public[0.1.2].
    - cvuorinen/phpdoc-markdown-public 0.1.2 requires phpdocumentor/phpdocumentor ~2.8.0 -> satisfiable by phpdocumentor/phpdocumentor[v2.8.0, v2.8.1, v2.8.2, v2.8.3, v2.8.4, v2.8.5] but these conflict with your requirements or minimum-stability.

Is there a newer version of this package I should be using?

@cvuorinen
Copy link
Owner

Ah, sorry. I thought I had defined a version that allows minor updates. I'll fix it and make a new release.

@cvuorinen
Copy link
Owner

I released a new version that allows updating to phpdocumentor 2.9.

@jdrydn
Copy link
Author

jdrydn commented Jan 8, 2018

Sadly, updating phpdocumentor to 2.9 didn't solve this for me, so my workaround currently is:

{
  "name": "my/awesome/library",
  "version": "1.0.0",
  "scripts": {
    "phpdoc": [
      "php vendor/bin/phpdoc",
      "sed -i -e 's/\\\\My\\\\Awesome\\\\Library\\\\string/string/' -e 's/\\\\My\\\\Awesome\\\\Library\\\\array/array/' phpdocs/README.md"
    ]
  }
}
$ composer run-script phpdoc

¯\_(ツ)_/¯

@cvuorinen
Copy link
Owner

Ok, I set up a test of my own and I see the same result even with phpdocumentor 2.9. I'll look into it to see if I can figure out a way to fix it.

Meanwhile, another workaround is to have an actual DocBlock comment that has type string, then it works correctly.

@jdrydn
Copy link
Author

jdrydn commented Jan 10, 2018

@cvuorinen Yeah, much better than a sed command. I don't have a lot of files in this project so I'm happy with that as a solution.

@cvuorinen
Copy link
Owner

Seems like this should be fixed in phpDocumentor 3 but it's still WIP.

This release should be able to parse your php 7+ projects without issues. We are still working on new features to be implemented like parsing of return types and scalar type hints.

from https://github.com/phpDocumentor/phpDocumentor2/releases/tag/v3.0.0-alpha1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants