1

I have a big project in php 5 and it's well documented. Now, I want to migrate to php 7.2 and I have already checked the compatibility using phpstan and every thing is alright. So, I wonder if there is a tool that could automatically transform the php 5 annotations to php 7 (like functions declarations and variables )?

Thanks in advance

Ahmed
  • 15
  • 5
  • 4
    Can you show examples of what you want to convert. Annotations aren't something which I would have thought are directly related to the version of PHP. – Nigel Ren Jun 01 '21 at 09:41

2 Answers2

1

Aside from php-cs-fixer, also have a look at Rector. It offers much more advanced rules and allows you to create your own.

M. de Boer
  • 51
  • 4
0

If you are looking to convert phpdoc param types to typehints, you can use php-cs-fixer that includes this kind of feature : phpdoc_to_param_type

There is also a fixer for function return types : phpdoc_to_return_type

Example from the php-cs-fixer documentation :

<?php

/** @param string|null $bar */
function my_foo($bar)
{}

will become

<?php

/** @param string|null $bar */
function my_foo(?string $bar)
{}

beware, those features are tagged as experimental so you should always double check what has been done.

ᴄʀᴏᴢᴇᴛ
  • 2,939
  • 26
  • 44
  • Thanks man. This is kind of what I am looking for. So I will try it. Is there any thing like that for variables? – Ahmed Jun 01 '21 at 11:57