Giter Club home page Giter Club logo

php-backslasher's Introduction

Build Status Scrutinizer Code Quality SensioLabsInsight Latest Stable Version Total Downloads License Donate

PHP BackSlasher

Tool to add all PHP internal functions and constants to its namespace by adding backslash to them.

Function resolution without the backslash forces the PHP internals to verify for each function call if function or constant belongs to current namespace or the global namespace. With the backslash PHP does not check the current namespace and therefore execution is faster when using OP Cache.

Idea from Nikita Popov talk:

Installation

Use Composer to install the package:

$ composer require --dev nilportugues/php_backslasher

Usage

$ php bin/php_backslasher fix <path/to/directory>

Output

Works for functions in conditional statements, negative conditionals, placed in an array as key or value and any other normal use. Also adds a backslash to defined constants and true, false and null values.

Internal functions and constants

echo strlen('Hello World');
var_dump(null);
var_dump(false);
echo DIRECTORY_SEPARATOR;
return true;

// becomes:
echo \strlen('Hello World');
\var_dump(\null);
\var_dump(\false);
echo \DIRECTORY_SEPARATOR;
return \true;

Contribute

Contributions to the package are always welcome!

Support

Get in touch with me using one of the following means:

Authors

License

The code base is licensed under the MIT license.

php-backslasher's People

Contributors

desure85 avatar flavioheleno avatar k00ni avatar nilportugues avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-backslasher's Issues

Add tests for constants

Better testing for constants

Self::DIRECTORY_SEPARATOR may be slashed when it shouldnt...

Add PHP 7.4 support

The current release does not support PHP 7.4 (check below).

flavio@homer:~/php-backslasher$ ./vendor/bin/phpunit tests/
PHPUnit 5.7.27 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.4.4
Configuration: /Users/flavio/php-backslasher/phpunit.xml.dist
Error:         No code coverage driver is available

EEEEE                                                               5 / 5 (100%)

Time: 97 ms, Memory: 4.00MB

There were 5 errors:

1) NilPortugues\Tests\BackslashFixer\Fixer\FileEditorTest::testItCanBackSlashBooleansAndAndNull
"continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?

/Users/flavio/php-backslasher/vendor/zendframework/zend-code/src/Generator/FileGenerator.php:135
/Users/flavio/php-backslasher/tests/Fixer/FileEditorTest.php:47

2) NilPortugues\Tests\BackslashFixer\Fixer\FileEditorTest::testItCanBackSlashConstants
"continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?

/Users/flavio/php-backslasher/vendor/zendframework/zend-code/src/Generator/FileGenerator.php:135
/Users/flavio/php-backslasher/tests/Fixer/FileEditorTest.php:47

3) NilPortugues\Tests\BackslashFixer\Fixer\FileEditorTest::testItCanBackSlashFunctions
"continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?

/Users/flavio/php-backslasher/vendor/zendframework/zend-code/src/Generator/FileGenerator.php:135
/Users/flavio/php-backslasher/tests/Fixer/FileEditorTest.php:47

4) NilPortugues\Tests\BackslashFixer\Fixer\FileEditorTest::testItDoesNotBackSlashFunctionsFromImportedFunctions
"continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?

/Users/flavio/php-backslasher/vendor/zendframework/zend-code/src/Generator/FileGenerator.php:135
/Users/flavio/php-backslasher/tests/Fixer/FileEditorTest.php:47

5) NilPortugues\Tests\BackslashFixer\Fixer\FileEditorTest::testItDoesNotBackSlashAliasedFunctions
"continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?

/Users/flavio/php-backslasher/vendor/zendframework/zend-code/src/Generator/FileGenerator.php:135
/Users/flavio/php-backslasher/tests/Fixer/FileEditorTest.php:47

ERRORS!
Tests: 5, Assertions: 0, Errors: 5.

I've tracked down the problem to be within Zend-Code.

flavio@homer:~/php-backslasher$ php -v
PHP 7.4.4 (cli) (built: Apr  6 2020 12:54:21) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

replacement

Hi !
Idea behind this package is really great!

This package is not actively maintained, and
some time ago, one of open-source contributor bring this feature into https://github.com/FriendsOfPHP/PHP-CS-Fixer/ as native_function_invocation rule.

Maybe you want to deprecate this package and redirect users to PHP CS Fixer to not need to maintain this package ?

Look for autoload file

Bootstrap should look for autoload file
Composer should be compiled into the generated Phar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.