Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeraymonddowning committed Nov 10, 2020
1 parent ee778e1 commit d8c6494
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 98 deletions.
1 change: 1 addition & 0 deletions .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
C:37:"PHPUnit\Runner\DefaultTestResultCache":596:{a:2:{s:7:"defects";a:2:{s:94:"RicorocksDigitalAgency\GiveAnInch\Tests\ExampleTest::it_calculates_the_distance_between_points";i:4;s:94:"RicorocksDigitalAgency\Giveaninch\Tests\ExampleTest::it_calculates_the_distance_between_points";i:3;}s:5:"times";a:3:{s:94:"RicorocksDigitalAgency\GiveAnInch\Tests\ExampleTest::it_calculates_the_distance_between_points";d:0.032;s:94:"RicorocksDigitalAgency\Giveaninch\Tests\ExampleTest::it_calculates_the_distance_between_points";d:0.041;s:103:"RicorocksDigitalAgency\Giveaninch\Tests\ExampleTest::it_can_say_if_something_is_within_a_certain_radius";d:0.037;}}}
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
],
"require": {
"php": "^7.1",
"illuminate/support": "^6.0"
"illuminate/support": "^6.0|^7.0|^8.0"
},
"require-dev": {
"orchestra/testbench": "^4.0",
Expand All @@ -30,7 +30,7 @@
},
"autoload-dev": {
"psr-4": {
"RicorocksDigitalAgency\\Giveaninch\\Tests\\": "tests"
"RicorocksDigitalAgency\\Giveaninch\\\\Tests\\": "tests"
}
},
"scripts": {
Expand All @@ -44,10 +44,10 @@
"extra": {
"laravel": {
"providers": [
"RicorocksDigitalAgency\\Giveaninch\\GiveaninchServiceProvider"
"GiveAnInchServiceProvider"
],
"aliases": {
"Giveaninch": "RicorocksDigitalAgency\\Giveaninch\\GiveaninchFacade"
"Giveaninch": "GiveAnInch"
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/Facades/GiveAnInch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace RicorocksDigitalAgency\Giveaninch\Facades;

use Illuminate\Support\Facades\Facade;

class GiveAnInch extends Facade
{
protected static function getFacadeAccessor()
{
return 'giveaninch';
}
}
41 changes: 41 additions & 0 deletions src/GiveAnInch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace RicorocksDigitalAgency\Giveaninch;

class GiveAnInch
{
protected $fromLat, $fromLng;
protected $toLat, $toLng;

public function from($lat, $lng)
{
$this->fromLat = $lat;
$this->fromLng = $lng;

return $this;
}

public function to($lat, $lng)
{
$this->toLat = $lat;
$this->toLng = $lng;

return $this;
}

public function getDistance()
{
$ky = 40000 / 360;
$kx = cos(pi() * $this->fromLat / 180.0) * $ky;
$dy = abs($this->fromLat - $this->toLat) * $ky;
$dx = abs($this->fromLng - $this->toLng) * $kx;

return sqrt($dx * $dx + $dy * $dy);
}

public function isWithin(float $radius)
{
return $this->getDistance() < $radius;
}

}
32 changes: 32 additions & 0 deletions src/GiveAnInchServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace RicorocksDigitalAgency\Giveaninch;

use Illuminate\Support\ServiceProvider;

class GiveAnInchServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*/
public function boot()
{
if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__.'/../config/config.php' => config_path('giveaninch.php'),
], 'config');
}
}

/**
* Register the application services.
*/
public function register()
{
$this->mergeConfigFrom(__DIR__.'/../config/config.php', 'giveaninch');

$this->app->bind('giveaninch', function () {
return new GiveAnInch;
});
}
}
8 changes: 0 additions & 8 deletions src/Giveaninch.php

This file was deleted.

21 changes: 0 additions & 21 deletions src/GiveaninchFacade.php

This file was deleted.

60 changes: 0 additions & 60 deletions src/GiveaninchServiceProvider.php

This file was deleted.

12 changes: 12 additions & 0 deletions src/Within.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php


namespace RicorocksDigitalAgency\Giveaninch;


class Within
{
public function __construct($fromLat, $fromLng, $toLat, $toLng)
{
}
}
20 changes: 15 additions & 5 deletions tests/ExampleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,29 @@
namespace RicorocksDigitalAgency\Giveaninch\Tests;

use Orchestra\Testbench\TestCase;
use RicorocksDigitalAgency\Giveaninch\GiveaninchServiceProvider;
use RicorocksDigitalAgency\Giveaninch\Facades\GiveAnInch;
use RicorocksDigitalAgency\Giveaninch\GiveAnInchServiceProvider;

class ExampleTest extends TestCase
{

protected function getPackageProviders($app)
{
return [GiveaninchServiceProvider::class];
return [GiveAnInchServiceProvider::class];
}


/** @test */
public function it_calculates_the_distance_between_points()
{
$this->assertEquals(0, GiveAnInch::from(0, 0)->to(0, 0)->getDistance());
$this->assertEquals(1571.3484026368, GiveAnInch::from(0, 0)->to(10, 10)->getDistance());
$this->assertEquals(15530.564562899437, GiveAnInch::from(-5, -50)->to(70, 68.4)->getDistance());
}

/** @test */
public function true_is_true()
public function it_can_say_if_something_is_within_a_certain_radius()
{
$this->assertTrue(true);
$this->assertTrue(GiveAnInch::from(0, 0)->to(0, 0)->isWithin(5));
$this->assertFalse(GiveAnInch::from(0, 0)->to(100, 100)->isWithin(5));
}
}

0 comments on commit d8c6494

Please sign in to comment.