Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notice #12

Closed
marcelloh opened this issue Apr 12, 2017 · 5 comments
Closed

Notice #12

marcelloh opened this issue Apr 12, 2017 · 5 comments
Assignees

Comments

@marcelloh
Copy link

marcelloh commented Apr 12, 2017

While running your code against mine
Notice: Uninitialized string offset: 1 in C:\data\QualityReport\vendor\wapmorgan\php-code-fixer\src\PhpCodeFixer.php on line 177

@marcelloh
Copy link
Author

I debugged a bit:
The notice is on traits

@wapmorgan
Copy link
Owner

Can you post this trait here?

@marcelloh
Copy link
Author

<?php

namespace Illuminate\Support\Traits;

use Closure;
use BadMethodCallException;

trait Macroable
{
    /**
     * The registered string macros.
     *
     * @var array
     */
    protected static $macros = [];

    /**
     * Register a custom macro.
     *
     * @param  string    $name
     * @param  callable  $macro
     * @return void
     */
    public static function macro($name, callable $macro)
    {
        static::$macros[$name] = $macro;
    }

    /**
     * Checks if macro is registered.
     *
     * @param  string  $name
     * @return bool
     */
    public static function hasMacro($name)
    {
        return isset(static::$macros[$name]);
    }

    /**
     * Dynamically handle calls to the class.
     *
     * @param  string  $method
     * @param  array   $parameters
     * @return mixed
     *
     * @throws \BadMethodCallException
     */
    public static function __callStatic($method, $parameters)
    {
        if (! static::hasMacro($method)) {
            throw new BadMethodCallException("Method {$method} does not exist.");
        }

        if (static::$macros[$method] instanceof Closure) {
            return call_user_func_array(Closure::bind(static::$macros[$method], null, static::class), $parameters);
        }

        return call_user_func_array(static::$macros[$method], $parameters);
    }

    /**
     * Dynamically handle calls to the class.
     *
     * @param  string  $method
     * @param  array   $parameters
     * @return mixed
     *
     * @throws \BadMethodCallException
     */
    public function __call($method, $parameters)
    {
        if (! static::hasMacro($method)) {
            throw new BadMethodCallException("Method {$method} does not exist.");
        }

        if (static::$macros[$method] instanceof Closure) {
            return call_user_func_array(static::$macros[$method]->bindTo($this, static::class), $parameters);
        }

        return call_user_func_array(static::$macros[$method], $parameters);
    }
}

@wapmorgan
Copy link
Owner

Thanks for feedback! Fixed in 2.0.5. Please, upgrade and test your code.

@wapmorgan wapmorgan self-assigned this Apr 24, 2017
@marcelloh
Copy link
Author

I finally got the time to test, and you fixed it :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants