Giter Site home page Giter Site logo

dg / composer-backslasher Goto Github PK

View Code? Open in Web Editor NEW
40.0 10.0 3.0 19 KB

Composer plugin that speeds up your application by adding backslashes to all PHP internal functions and constants.

Home Page: https://nette.org

PHP 100.00%
composer composer-plugin performance

composer-backslasher's Introduction

Composer Backslasher

Downloads this Month Build Status

Composer plugin that speeds up your application by adding backslashes to all PHP internal functions and constants in /vendor. Does not modify files of your application.

Installation

composer require dg/composer-backslasher

Then simply use composer update.

How it works?

It simply turns this code:

namespace A;

if (preg_match('/(foo)(bar)(baz)/', 'foobarbaz', $matches, PREG_OFFSET_CAPTURE)) {
	// ...
}

into this code:

namespace A;

if (\preg_match('/(foo)(bar)(baz)/', 'foobarbaz', $matches, \PREG_OFFSET_CAPTURE)) {
	// ...
}

to avoid double lookup for global functions and constants.

Configuration

If you want to ignore certain functions or constants, specify them in the configuration. Simply add a extra > backslasher-ignore section to composer.json file:

{
	"extra": {
		"backslasher-ignore": [
			"GuzzleHttp\\Promise\\each"
		]
	}
}

Support Project

Do you like Composer Backslasher? Are you looking forward to the new features?

Donate

composer-backslasher's People

Contributors

davidkudera avatar dg avatar gondo 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

composer-backslasher's Issues

doesn't change files

  • bug report? yes
  • feature request? no

Description

after installing this package and running composer update, i can see the message "Composer Backslasher: Added 39 backslashes." but in reality no file has changed (i have nothing to commit)

Steps To Reproduce

  1. run composer require dg/composer-backslasher
  2. git status:
	modified:   composer.json
	modified:   composer.lock
	modified:   symfony.lock
  1. run composer update
  2. see "Composer Backslasher: Added 39 backslashes."
  3. git status:
	modified:   composer.json
	modified:   composer.lock
	modified:   symfony.lock
  1. ๐Ÿค”

wrong parsing

  • bug report? yes
  • feature request? no

Description

backslash is added to the function name and it breaks the application
public static function NAN() became public static function \NAN()

Steps To Reproduce

define function with name public static function NAN() in vendor
(f.e. "phpoffice/phpspreadsheet": "^1.1")
include this package and run composer update
code will change to public static function \NAN()

Local function overriding the one from PHP API

  • bug report? yes
  • feature request? yes

Description

This tool is incompatible with package https://github.com/guzzle/promises which override PHP function each by its own version (and maybe some other).

Steps To Reproduce

Use library with following content:

<?php
namespace A;

function settle($promises)
{
    $results = [];
    return each(
        $promises,
        function () {},
        function () {}
    )->then(function () use (&$results) {
        ksort($results);
        return $results;
    });
}

function each(
    $iterable,
    callable $onFulfilled = null,
    callable $onRejected = null
) {
    return 'baz';
}

Expected result after processed by this tool

<?php
namespace A;

function settle($promises)
{
    $results = [];
    return each(
        $promises,
        function () {},
        function () {}
    )->then(function () use (&$results) {
        \ksort($results);
        return $results;
    });
}

function each(
    $iterable,
    callable $onFulfilled = null,
    callable $onRejected = null
) {
    return 'baz';
}

What is produced instead

<?php
namespace A;

function settle($promises)
{
    $results = [];
    return \each( // notice this back slash, targeting global method instead local one
        $promises,
        function () {},
        function () {}
    )->then(function () use (&$results) {
        \ksort($results);
        return $results;
    });
}

function each(
    $iterable,
    callable $onFulfilled = null,
    callable $onRejected = null
) {
    return 'baz';
}

Proposed solution

  • Add possibility to blacklist some directories
  • Check existence of overriding functions

add to require-dev instead of require

  • bug report? no
  • feature request? no

Description

this package is useful in dev environment but useless in any other (testing, production, ...)
i would even say it is harmful in production as it has to be autoloaded

Suggestion

install via composer require dg/composer-backslasher --dev

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.