Fixed xf-dev:class-use-function sometimes generates bad 'use function' statements

Xon

Well-known member
Affected version
2.2.8 Patch 1
It looks like xf-dev:class-use-function gets confused if there are comments before the namespace declaration, and when non-white listed functions are in an existing 'use function' statement.

Given this code;
PHP:
<?php
/**
 * @noinspection PhpMissingReturnTypeInspection
 */

namespace SV\Example;

use \XF\App;

I've seen it generate;
PHP:
<?php
const USE_FUNCTION_PLACEHOLDER = true;
/**
 * @noinspection PhpMissingReturnTypeInspection
 */

namespace SV\Example;

use \XF\App;
or
PHP:
<?php
use function count;
/**
 * @noinspection PhpMissingReturnTypeInspection
 */

namespace SV\Example;

use \XF\App;

If a non-whitelisted function is in the 'use function' list it strips it out, and can generate undesired code;
PHP:
<?php

namespace SV\Example;

use \XF\App;
use function is_callable;

Results in;
PHP:
<?php

namespace SV\Example;

use \XF\App;
const USE_FUNCTION_PLACEHOLDER = true;
 
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.2.16).

Change log:
Fix some issues with xf-dev:class-use-function to better support classes with class attributes and comments, or existing use function declarations.
There may be a delay before changes are rolled out to the XenForo Community.
 
Back
Top Bottom