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

Public methods count #335

Closed
jakagacic opened this issue Dec 9, 2017 · 3 comments
Closed

Public methods count #335

jakagacic opened this issue Dec 9, 2017 · 3 comments
Labels

Comments

@jakagacic
Copy link

Hi, I have noticed that the public methods count does not recognize getters and setters when using php7 type declarations for parameters and return types. This makes it very easy to get the following error on a good structured class, with a few private properties:

Blob / God object error
A blob object (or "god class") does not follow the Single responsability principle.

  • object has lot of public methods (8, excluding getters and setters)

Is there any chance for this to be fixed?

@UFOMelkor
Copy link
Member

Hi @jakagacic,

may I ask you for an example?
I added the following examples to the RoleOfMethodDetectorTest and both are recognized correctly:

$examples[] = ['getter', '<?php class A { function getName(): string { return $this->name; } }'];
$examples[] = ['setter', '<?php class A { function setName(string $name): void { $this->name = $name; } }'];

@jakagacic
Copy link
Author

jakagacic commented Dec 13, 2017

Hi @UFOMelkor,

thank you for your answer.

I have testes both of your examples and they work as expected, but the problem seems to be when using types other then the primary ones. For example, this setter is recognized:

    /**
     * @param string $role
     */
    public function setRole(string $role)
    {
        $this->role = $role;
    }

while this one isn't:

    /**
     * @param Role $role
     */
    public function setRole(Role $role)
    {
        $this->role = $role;
    }

@UFOMelkor
Copy link
Member

Thank your for your example, I could reproduce the error with them. I will try to find a fix for it tomorrow.

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

No branches or pull requests

2 participants