Skip to content

Commit

Permalink
[Location] Added type hints and test. (#1586)
Browse files Browse the repository at this point in the history
  • Loading branch information
siad007 authored Apr 24, 2021
1 parent cab6d58 commit 1152fcf
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/Phing/Parser/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,40 +65,40 @@ public function __construct($fileName = null, $lineNumber = null, $columnNumber
*
* @return string the string representation of this Location object
*/
public function __toString()
public function __toString(): string
{
$buf = '';
if (null !== $this->fileName) {
$buf .= $this->fileName;
if (null !== $this->lineNumber) {
$buf .= ':' . $this->lineNumber;
if (null !== $this->getFileName()) {
$buf .= $this->getFileName();
if (null !== $this->getLineNumber()) {
$buf .= ':' . $this->getLineNumber();
}
$buf .= ':' . $this->columnNumber;
$buf .= ':' . $this->getColumnNumber();
}

return (string) $buf;
return $buf;
}

/**
* @return null|string
*/
public function getFileName()
public function getFileName(): ?string
{
return $this->fileName;
}

/**
* @return null|int
*/
public function getLineNumber()
public function getLineNumber(): ?int
{
return $this->lineNumber;
}

/**
* @return null|int
*/
public function getColumnNumber()
public function getColumnNumber(): ?int
{
return $this->columnNumber;
}
Expand Down
45 changes: 45 additions & 0 deletions tests/Phing/Parser/LocationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/**
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/

namespace Phing\Test\Parser;

use Phing\Parser\Location;
use PHPUnit\Framework\TestCase;

class LocationTest extends TestCase
{
/**
* @test
* @dataProvider locations
*/
public function location($fileName, $lineNumber, $columnNumber): void
{
$loc = new Location($fileName, $lineNumber, $columnNumber);
$this->assertSame(sprintf('%s:%s:%s', $fileName, $lineNumber, $columnNumber), (string) $loc);
}

public function locations(): array
{
return [
'normal' => ['test.php', 10, 20],
'negative' => ['test.php', -10, -20]
];
}
}

0 comments on commit 1152fcf

Please sign in to comment.