Skip to content
This repository has been archived by the owner on Dec 3, 2023. It is now read-only.

Commit

Permalink
[CodingStandard] Deprecated ImportNamespacedNameFixer, use SlevomatCo…
Browse files Browse the repository at this point in the history
…dingStandard\Sniffs\Namespaces\ReferenceUsedNamesOnlySniff instaed [closes #625]
  • Loading branch information
TomasVotruba committed Sep 14, 2018
1 parent aad50fb commit ba34531
Show file tree
Hide file tree
Showing 47 changed files with 13 additions and 643 deletions.
1 change: 1 addition & 0 deletions ecs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ parameters:
- 'packages/CodingStandard/src/Sniffs/Naming/ClassNameSuffixByParentSniff.php'
# class might not exist
- '*packages/EasyCodingStandard/src/DependencyInjection/CompilerPass/*CompilerPass.php'
- 'packages/CodingStandard/src/Fixer/Import/ImportNamespacedNameFixer.php'
# tests
- 'packages/TokenRunner/tests/Wrapper/FixerWrapper/ClassWrapper/ClassWrapperTest.php'

Expand Down
57 changes: 0 additions & 57 deletions packages/CodingStandard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,63 +95,6 @@ services:
+require __DIR__.'/vendor/autoload.php';
```

### Types should not be referenced via a fully/partially qualified name, but via a use statement

- :wrench:
- class: [`Symplify\CodingStandard\Fixer\Import\ImportNamespacedNameFixer`](src/Fixer/Import/ImportNamespacedNameFixer.php)

```diff
namespace SomeNamespace;

+use AnotherNamespace\AnotherType;

class SomeClass
{
public function someMethod()
{
- return new \AnotherNamespace\AnotherType;
+ return new AnotherType;
}
}
```

This checker imports single name classes like `\Twig_Extension` or `\SplFileInfo` by default. But if you need, you can **configure it**:

```yaml
# ecs.yml
services:
Symplify\CodingStandard\Fixer\Import\ImportNamespacedNameFixer:
allow_single_names: true # false by default
```

You can also configure to check `/** @var Namespaced\DocBlocks */` as well:

```yaml
# ecs.yml
services:
Symplify\CodingStandard\Fixer\Import\ImportNamespacedNameFixer:
include_doc_blocks: true # false by default
```

And what about duplicate class name? They are uniquized by vendor name:

```php
<?php declare(strict_types=1);

namespace SomeNamespace;

use Nette\Utils\Finder as NetteFinder;
use Symfony\Finder\Finder;

class SomeClass
{
public function create(NetteFinder $someClass)
{
return new Finder;
}
}
```

### Parameters, arguments and array items should be on the same/standalone line to fit line length

- :wrench:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
use Symplify\TokenRunner\Naming\Name\NameAnalyzer;
use Symplify\TokenRunner\Naming\Name\NameFactory;
use Symplify\TokenRunner\Transformer\FixerTransformer\UseImportsTransformer;
use function Safe\sleep;
use function Safe\sprintf;

/**
* Possible cases:
Expand Down Expand Up @@ -119,6 +121,16 @@ public function __construct(
->resolve([]);
$this->phpDocInfoPrinter = $phpDocInfoPrinter;
$this->phpDocInfoFactory = $phpDocInfoFactory;

trigger_error(
sprintf(
'"%s" was deprecated and will be removed in Symplify\CodingStandard 5.0. Use "%s" instead."',
self::class,
'SlevomatCodingStandard\Sniffs\Namespaces\ReferenceUsedNamesOnlySniff'
),
E_USER_DEPRECATED
);
sleep(3); // inspired at "deprecated interface" Tweet
}

public function getDefinition(): FixerDefinitionInterface
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit ba34531

Please sign in to comment.