Skip to content

Commit

Permalink
Merge pull request #1 from webparking/add-phpstan
Browse files Browse the repository at this point in the history
Added phpstan
  • Loading branch information
allebb authored Feb 7, 2020
2 parents 6517da3 + 4728402 commit 293c49a
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 29 deletions.
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "4.8.*"
"phpunit/phpunit": "4.8.*",
"phpstan/phpstan": "^0.12.9"
},
"autoload": {
"psr-4": {
"Ballen\\Distical\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
}
}
41 changes: 40 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
level: max
ignoreErrors:
-
message: '#Method .* has no return typehint specified#'
path: tests/*
8 changes: 4 additions & 4 deletions src/Calculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ class Calculator

/**
* LatLon points to measure between.
* @var array
* @var Entities\LatLong[]
*/
private $points;

/**
* The constructor
* @param \Ballen\Distical\LatLong $pointA Optional initial point.
* @param \Ballen\Distical\LatLong $pointB Optional final point.
* @param Entities\LatLong $pointA Optional initial point.
* @param Entities\LatLong $pointB Optional final point.
*/
public function __construct($pointA = null, $pointB = null)
{
Expand Down Expand Up @@ -62,7 +62,7 @@ public function addPoint(LatLong $point, $key = null)
/**
* Remove a lat/long co-ordinate from the points collection.
* @param int|string $key The name or ID of the point key.
* @throws InvalidArgumentException
* @throws \InvalidArgumentException
* @return \Ballen\Distical\Calculator
*/
public function removePoint($key = null)
Expand Down
6 changes: 4 additions & 2 deletions src/Entities/Distance.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ class Distance

/**
* The distance in kilometres
* @var double|int
*/
private $kilometres;

/**
* Class constructor
* @param double $kilometres The distance in kilometres.
* @param mixed $kilometres The distance in kilometres.
*/
public function __construct($kilometres = 0)
{
Expand All @@ -44,8 +45,9 @@ public function __construct($kilometres = 0)

/**
* Validates the distance constructor value.
* @param mixed $distance
* @param mixed $distance
* @throws \InvalidArgumentException
* @return void
*/
private function validateDistance($distance)
{
Expand Down
5 changes: 0 additions & 5 deletions src/Exceptions/InvalidLatitudeFormatException.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,4 @@
*/
class InvalidLatitudeFormatException extends \Exception
{

public function __construct($message, $code = 0, Exception $previous = null)
{
parent::__construct($message, $code, $previous);
}
}
5 changes: 0 additions & 5 deletions src/Exceptions/InvalidLongitudeFormatException.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,4 @@
*/
class InvalidLongitudeFormatException extends \Exception
{

public function __construct($message, $code = 0, Exception $previous = null)
{
parent::__construct($message, $code, $previous);
}
}
8 changes: 5 additions & 3 deletions tests/DistanceEntityTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace Tests;

/**
* Distical
*
Expand All @@ -15,9 +17,9 @@
*/
use \Ballen\Distical\Entities\Distance;

class DistanceEntityTest extends PHPUnit_Framework_TestCase
class DistanceEntityTest extends \PHPUnit_Framework_TestCase
{

/** @var Distance */
protected $entity;

public function __construct()
Expand All @@ -27,7 +29,7 @@ public function __construct()

public function testEntityCreation()
{
$this->assertInstanceOf('Ballen\Distical\Entities\Distance', $this->entity);
$this->assertInstanceOf(Distance::class, $this->entity);
}

public function testInvalidEntityCreationWithAsString()
Expand Down
12 changes: 10 additions & 2 deletions tests/DisticalTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace Tests;

/**
* Distical
*
Expand All @@ -16,12 +18,18 @@
use \Ballen\Distical\Calculator;
use \Ballen\Distical\Entities\LatLong;

class DisticalTest extends PHPUnit_Framework_TestCase
class DisticalTest extends \PHPUnit_Framework_TestCase
{

/** @var LatLong */
protected $latlong1;

/** @var LatLong */
protected $latlong2;

/** @var LatLong */
protected $latlong3;

/** @var LatLong */
protected $latlong4;

public function __construct()
Expand Down
18 changes: 12 additions & 6 deletions tests/LatLongEntityTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace Tests;

/**
* Distical
*
Expand All @@ -15,11 +17,15 @@
*/
use \Ballen\Distical\Entities\LatLong;

class LatLongEntityTest extends PHPUnit_Framework_TestCase
class LatLongEntityTest extends \PHPUnit_Framework_TestCase
{

/** @var LatLong */
protected $entity;

/** @var float */
protected $test_lat = 52.005497;

/** @var float */
protected $test_lng = 1.045748;

public function __construct()
Expand Down Expand Up @@ -54,25 +60,25 @@ public function testAliasLngFromEntity()

public function testInvalidLatCoordValidation()
{
$this->setExpectedException('\Ballen\Distical\Exceptions\InvalidLatitudeFormatException', 'The latitude parameter is invalid, value must be between -90 and 90');
$this->setExpectedException(\Ballen\Distical\Exceptions\InvalidLatitudeFormatException::class, 'The latitude parameter is invalid, value must be between -90 and 90');
$test = new LatLong(-91, $this->test_lng);
}

public function testInvalidLonCoordValidation()
{
$this->setExpectedException('Ballen\Distical\Exceptions\InvalidLongitudeFormatException', 'The longitude parameter is invalid, value must be between -180 and 180');
$this->setExpectedException(\Ballen\Distical\Exceptions\InvalidLongitudeFormatException::class, 'The longitude parameter is invalid, value must be between -180 and 180');
$test = new LatLong($this->test_lat, 181);
}

public function testInvalidCoords()
{
$this->setExpectedException('Ballen\Distical\Exceptions\InvalidLatitudeFormatException', 'The latitude parameter is invalid, value must be between -90 and 90');
$this->setExpectedException(\Ballen\Distical\Exceptions\InvalidLatitudeFormatException::class, 'The latitude parameter is invalid, value must be between -90 and 90');
$test = new LatLong(-91, 251);
}

public function testValidCoords()
{
$test = new LatLong($this->test_lat, $this->test_lng);
$this->assertInstanceOf('\Ballen\Distical\Entities\LatLong', $test);
$this->assertInstanceOf(\Ballen\Distical\Entities\LatLong::class, $test);
}
}

0 comments on commit 293c49a

Please sign in to comment.