2

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.

miken32
  • 42,008
  • 16
  • 111
  • 154
Xyraphid
  • 23
  • 1
  • 5
  • For your first try, did you make sure you have no spaces after `sprintf(`? – miken32 May 15 '19 at 21:31
  • Thank you for your Help, thw problem is solved now. – Xyraphid May 17 '19 at 23:12
  • 2
    You should not mark an answer accepted if it did not answer your problems. Somebody having this problem in the future might be confused. If the problem cannot be reproduced, the question should be closed and deleted. – miken32 May 17 '19 at 23:43

1 Answers1

1

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
);
Nawwar Elnarsh
  • 1,049
  • 16
  • 28
  • Thank you for help...iam sure there were no space afer sprintf( ....I solved it now i think it was a Problem with the line endings in the file... – Xyraphid May 17 '19 at 22:44