Updated Rector to commit 36e9b6cf74173091196fd91c858f663e65bb9af1
36e9b6cf74
[build] remove docs from remote, to allow updates
@ -1,100 +0,0 @@
|
||||
# How To Work with Doc Block and Comments
|
||||
|
||||
Let's say we have a doc block:
|
||||
|
||||
```php
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
return 1000;
|
||||
}
|
||||
```
|
||||
|
||||
## How to get a Return Type?
|
||||
|
||||
To get e.g. return type, use `PhpDocInfo` value object with useful methods:
|
||||
|
||||
```php
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
||||
|
||||
/** @var PhpDocInfoFactory $phpDocInfoFactory */
|
||||
$phpDocInfo = $phpDocInfoFactory->createFromNodeOrEmpty($classMethod);
|
||||
|
||||
// then use any method you like
|
||||
$returnType = $phpDocInfo->getReturnType();
|
||||
// instance of "\PHPStan\Type\IntegerType"
|
||||
var_dump($returnType);
|
||||
```
|
||||
|
||||
## How to Remove node?
|
||||
|
||||
```php
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
|
||||
/** @var PhpDocInfo $phpDocInfo */
|
||||
$phpDocInfo->removeByType(ReturnTagValueNode::class);
|
||||
```
|
||||
|
||||
## How create PhpDocInfo for a new node?
|
||||
|
||||
In case you build a new node and want to work with its doc block, you need to create it first:
|
||||
|
||||
```php
|
||||
// the "PhpDocInfoFactory" service is already available in children of "AbstractRector"
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
||||
|
||||
/** @var PhpDocInfoFactory $phpDocInfoFactory */
|
||||
$phpDocInfo = $phpDocInfoFactory->createFromNodeOrEmpty($node);
|
||||
```
|
||||
|
||||
## How to get Param with Names and Types?
|
||||
|
||||
```php
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
|
||||
/** @var PhpDocInfo $phpDocInfo */
|
||||
$paramTypes = $phpDocInfo->getParamTypesByName();
|
||||
|
||||
/** @var array<string, Type> $paramTypes */
|
||||
var_dump($paramTypes);
|
||||
```
|
||||
|
||||
## How to Get Class Annotation?
|
||||
|
||||
Doctrine class annotations are annotations based on [`doctrine/annotations`](https://github.com/doctrine/annotations/) package. They are classes that have `@annotation`. Most common are Doctrine entity, column, one to many etc., but also Symfony route or Symfony validation annotations.
|
||||
|
||||
Let's look how to work one for Doctrine entity:
|
||||
|
||||
```php
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class UserEntity
|
||||
{
|
||||
}
|
||||
```
|
||||
|
||||
```php
|
||||
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
|
||||
/** @var PhpDocInfo $phpDocInfo */
|
||||
$entityTagValueNode = $phpDocInfo->findOneByAnnotationClass('Doctrine\ORM\Mapping\Entity');
|
||||
if (! $entityTagValueNode instanceof DoctrineAnnotationTagValueNode) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$annotationClass = $entityTagValueNode->identifierTypeNode;
|
||||
var_dump($annotationClass); // \PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode("Doctrine\ORM\Mapping\Entity")
|
||||
|
||||
$values = $entityTagValueNode->getValues();
|
||||
var_dump($values); // []
|
||||
```
|
Before Width: | Height: | Size: 8.7 KiB |
Before Width: | Height: | Size: 8.4 KiB |
Before Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 6.2 KiB |
Before Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 7.0 KiB |
Before Width: | Height: | Size: 6.0 KiB |
@ -17,12 +17,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'b1e22bb59aa41b69ea3d0a0632978d3082e83c76';
|
||||
public const PACKAGE_VERSION = '36e9b6cf74173091196fd91c858f663e65bb9af1';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2022-11-30 12:59:27';
|
||||
public const RELEASE_DATE = '2022-11-30 13:01:38';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
2
vendor/autoload.php
vendored
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit79895c5407566bbc3d4cd7a4900c5fbc::getLoader();
|
||||
return ComposerAutoloaderInit6c3c1d31f8651b2b098ab75e9acec244::getLoader();
|
||||
|
14
vendor/composer/autoload_real.php
vendored
@ -2,7 +2,7 @@
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit79895c5407566bbc3d4cd7a4900c5fbc
|
||||
class ComposerAutoloaderInit6c3c1d31f8651b2b098ab75e9acec244
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,19 +22,19 @@ class ComposerAutoloaderInit79895c5407566bbc3d4cd7a4900c5fbc
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit79895c5407566bbc3d4cd7a4900c5fbc', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit6c3c1d31f8651b2b098ab75e9acec244', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit79895c5407566bbc3d4cd7a4900c5fbc', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit6c3c1d31f8651b2b098ab75e9acec244', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit79895c5407566bbc3d4cd7a4900c5fbc::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit6c3c1d31f8651b2b098ab75e9acec244::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit79895c5407566bbc3d4cd7a4900c5fbc::$files;
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit6c3c1d31f8651b2b098ab75e9acec244::$files;
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequire79895c5407566bbc3d4cd7a4900c5fbc($fileIdentifier, $file);
|
||||
composerRequire6c3c1d31f8651b2b098ab75e9acec244($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
@ -46,7 +46,7 @@ class ComposerAutoloaderInit79895c5407566bbc3d4cd7a4900c5fbc
|
||||
* @param string $file
|
||||
* @return void
|
||||
*/
|
||||
function composerRequire79895c5407566bbc3d4cd7a4900c5fbc($fileIdentifier, $file)
|
||||
function composerRequire6c3c1d31f8651b2b098ab75e9acec244($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
8
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit79895c5407566bbc3d4cd7a4900c5fbc
|
||||
class ComposerStaticInit6c3c1d31f8651b2b098ab75e9acec244
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -3021,9 +3021,9 @@ class ComposerStaticInit79895c5407566bbc3d4cd7a4900c5fbc
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit79895c5407566bbc3d4cd7a4900c5fbc::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit79895c5407566bbc3d4cd7a4900c5fbc::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit79895c5407566bbc3d4cd7a4900c5fbc::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit6c3c1d31f8651b2b098ab75e9acec244::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit6c3c1d31f8651b2b098ab75e9acec244::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit6c3c1d31f8651b2b098ab75e9acec244::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|