phppsr-2

PSR-2 and "Line exceeds by 120 characters" for a Codeline


I'm trying to write some code to the PSR-2 PHP Standard.

At validation I get a lot of errors like this:

Line exceeds 120 characters; contains 122 characters

I've tried a few ways to fix this problem. Here is the original line:

$s = sprintf('%.2F %.2F %.2F %.2F re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op);

//Same Codeline with added spaces

$s = sprintf('%.2F %.2F %.2F %.2F re %s ', $this->x * $k, ($this->h - $this->y) * $k, $w * $k, -$h * $k, $op);

I tried to make it like this:

$s = sprintf(
   '%.2F %.2F %.2F %.2F re %s ',
    $this->x * $k,
    ($this->h - $this->y) * $k,
    $w * $k,
    -$h * $k,
    $op
);

But then the Error changed to "Opening parenthesis of a multi-line function call must be the last content on the line"

I also tried this:

$he1p = $this->x * $k;
$h3lp = ($this->h - $this->y) * $k;
$s = sprintf('%.2F %.2F %.2F %.2F re %s ', $he1p, $h3lp, $w * $k, -$h * $k, $op);

...but it seems like it shouldn't be needed to break it into multiple statements.


Solution

  • But then the Error changed to "Opening parenthesis of a multi-line function call must be the last content on the line"

    You have an empty space character after sprintf( while the last character in the line should be the opening parenthesis as the error states

    Try removing space after sprintf(

    $s = sprintf(
       '%.2F %.2F %.2F %.2F re %s ',
        $this->x * $k,
        ($this->h - $this->y) * $k,
        $w * $k,
        -$h * $k,
        $op
    );