diff --git a/config/drupal-8/drupal-8.7-deprecations.yml b/config/drupal-8/drupal-8.7-deprecations.yml index 705b2365..bf64490e 100644 --- a/config/drupal-8/drupal-8.7-deprecations.yml +++ b/config/drupal-8/drupal-8.7-deprecations.yml @@ -2,4 +2,5 @@ services: DrupalRector\Rector\Deprecation\FilePrepareDirectoryRector: ~ DrupalRector\Rector\Deprecation\FileCreateDirectoryRector: ~ + DrupalRector\Rector\Deprecation\FileUnmanagedCopyRector: ~ DrupalRector\Rector\Deprecation\FileExistsReplaceRector: ~ diff --git a/deprecation-index.yml b/deprecation-index.yml index ed75ea1e..0df1a92e 100644 --- a/deprecation-index.yml +++ b/deprecation-index.yml @@ -137,3 +137,8 @@ - DrupalRenderRootStaticUpdated.php - drupal_render_root.php - drupal_render_root_updated.php +'file_unmanaged_copy()': + Rector: FileUnmanagedCopyRector.php + PHPStan: 'Call to deprecated function file_unmanaged_copy(). Deprecated in Drupal 8.7.0, will be removed before Drupal 9.0.0. Use \Drupal\Core\File\FileSystemInterface::copy().' + Examples: + - file_unmanaged_copy.php \ No newline at end of file diff --git a/rector_examples/file_unmanaged_copy.php b/rector_examples/file_unmanaged_copy.php new file mode 100644 index 00000000..e08068bc --- /dev/null +++ b/rector_examples/file_unmanaged_copy.php @@ -0,0 +1,10 @@ +copy($source, $destination, $replace); +CODE_AFTER + ), + ]); + } + + /** + * @inheritdoc + */ + public function getNodeTypes(): array { + return [ + Node\Expr\FuncCall::class, + ]; + } + + /** + * @inheritdoc + */ + public function refactor(Node $node): ?Node { + if ($node->name instanceof Node\Name && 'file_unmanaged_copy' === (string) $node->name) { + $file_system_service = new Node\Expr\StaticCall(new Node\Name\FullyQualified('Drupal'), 'service', [new Node\Arg(new Node\Scalar\String_('file_system'))]); + + $method_name = 'copy'; + + $method = new Node\Identifier($method_name); + + $node = new Node\Expr\MethodCall($file_system_service, $method, $node->args); + + return $node; + + } + + return NULL; + } + +}