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

TypeHints.TypeHintDeclaration and traversableTypeHints #158

Closed
Fuco1 opened this issue May 29, 2017 · 7 comments
Closed

TypeHints.TypeHintDeclaration and traversableTypeHints #158

Fuco1 opened this issue May 29, 2017 · 7 comments

Comments

@Fuco1
Copy link

Fuco1 commented May 29, 2017

Hi.

I'm not sure how to configure this. I only got it working if I set fully qualified types in the codesniffer configuration and then use the same fully qualified type in the @var annotation. Is this expected behaviour? Shouldn't it infer the types based on the use declarations? Surely that is possible because the UnusedUses sniff does the resolutions somehow.

@kukulich
Copy link
Contributor

@Fuco1 Do you use last version? There was a bug that is fixed in last version.

@Fuco1
Copy link
Author

Fuco1 commented May 29, 2017

I use 2.4.1, should I use master?

@kukulich
Copy link
Contributor

No, dont use master, the bug was fixed in 2.4.1. Could you please post here your ruleset.xml and the code with traversable type hints?

@Fuco1
Copy link
Author

Fuco1 commented May 30, 2017

The php code is

<?php

namespace Entity\Renderers;

use Doctrine;
use Doctrine\ORM\Mapping as ORM;
use Entity;
use Fixtures;
use JsonSerializable;


/**
 * @ORM\Entity
 */
class RowTest extends Entity\Identified implements JsonSerializable, Fixtures\Serializable
{

	/**
	 * @ORM\OneToMany(targetEntity = "Item", mappedBy = "row", cascade = {"persist", "remove"})
	 * @ORM\OrderBy({"order" = "ASC"})
	 * @var Doctrine\Common\Collections\ArrayCollection
	 */
	protected $items;
}

Configuration

<?xml version="1.0"?>
<ruleset name="Standard">

    <rule ref="./vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/TypeHints/TypeHintDeclarationSniff.php" />
    <rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration">
      <properties>
        <property name="traversableTypeHints" type="array" value="
            \Doctrine\Common\Collections\ArrayCollection
        "/>
      </properties>
    </rule>

</ruleset>

When I use the \Doctrine\... type hint it properly highlights the error, but not with a relative type hint. (plus it actually marks use Doctrine as useless import if I turn on the UnusedUses sniff)

@kukulich
Copy link
Contributor

Should be fixed in release 2.4.2.

For UnusedUses sniff see settings: https://github.com/slevomat/coding-standard#slevomatcodingstandardnamespacesunuseduses-

@Fuco1
Copy link
Author

Fuco1 commented May 31, 2017

I confirm this works, thanks a lot for such a quick fix!

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants