Skip to content

Commit

Permalink
minor #4232 DX: remove Utils::splitLines (kubawerlos)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.12 branch.

Discussion
----------

DX: remove Utils::splitLines

This is the surprise mentioned [here](#4205 (comment)).

Class `Utils` is internal so no [backward compatibility](https://symfony.com/doc/current/contributing/code/bc.html) break.

Commits
-------

4cf6902 DX: remove Utils::splitLines
  • Loading branch information
keradus committed Jan 4, 2019
2 parents 75797f6 + 4cf6902 commit 4e56b05
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 54 deletions.
4 changes: 2 additions & 2 deletions src/DocBlock/DocBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace PhpCsFixer\DocBlock;

use PhpCsFixer\Utils;
use PhpCsFixer\Preg;

/**
* This class represents a docblock.
Expand Down Expand Up @@ -44,7 +44,7 @@ class DocBlock
*/
public function __construct($content)
{
foreach (Utils::splitLines($content) as $line) {
foreach (Preg::split('/([^\n\r]+\R*)/', $content, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $line) {
$this->lines[] = new Line($line);
}
}
Expand Down
19 changes: 0 additions & 19 deletions src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,6 @@ public static function cmpInt($a, $b)
return $a < $b ? -1 : 1;
}

/**
* Split a multi-line string up into an array of strings.
*
* We're retaining a newline character at the end of non-blank lines, and
* discarding other lines, so this function is unsuitable for anyone for
* wishing to retain the exact number of line endings. If a single-line
* string is passed, we'll just return an array with a element.
*
* @param string $content
*
* @return string[]
*/
public static function splitLines($content)
{
Preg::matchAll("/[^\n\r]+[\r\n]*/", $content, $matches);

return $matches[0];
}

/**
* Calculate the trailing whitespace.
*
Expand Down
33 changes: 0 additions & 33 deletions tests/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,39 +90,6 @@ public function provideCmpIntCases()
];
}

/**
* @param array $expected
* @param string $input
*
* @dataProvider provideSplitLinesCases
*/
public function testSplitLines(array $expected, $input)
{
$this->assertSame($expected, Utils::splitLines($input));
}

public function provideSplitLinesCases()
{
return [
[
["\t aaa\n", " bbb\n", "\t"],
"\t aaa\n bbb\n\t",
],
[
["aaa\r\n", " bbb\r\n"],
"aaa\r\n bbb\r\n",
],
[
["aaa\r\n", " bbb\n"],
"aaa\r\n bbb\n",
],
[
["aaa\r\n\n\n\r\n", " bbb\n"],
"aaa\r\n\n\n\r\n bbb\n",
],
];
}

/**
* @param string $spaces
* @param array|string $input token prototype
Expand Down

4 comments on commit 4e56b05

@voku
Copy link
Contributor

@voku voku commented on 4e56b05 Jan 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what I see when I use the ".phar"-file: here "@internal" is not available, but I don't know if this is a phar or a PhpStorm problem?

use PhpCsFixer\Fixer\FixerInterface;
use PhpCsFixer\Tokenizer\Token;








final class Utils
{
...

@keradus
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

phar shall be considered as binary file. don't try to analyse it directly.

@voku
Copy link
Contributor

@voku voku commented on 4e56b05 Jan 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understand and thanks for the reply. But PhpStorm did the analyse for me, so I didn't notice that this class was internal. I replaced my broken code and for me it's ok, but I wanted to report it. :)

@kubawerlos
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right click -> exclude phar from project

Please sign in to comment.