Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
10 / 10
WeatherAPIController
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
10 / 10
 initialize
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 indexActionGet
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
7 / 7
<?php
namespace Abbe\Controller;
use Abbe\Models\OpenWeather;
use Anax\Commons\ContainerInjectableInterface;
use Anax\Commons\ContainerInjectableTrait;
use Exception;
class WeatherAPIController implements ContainerInjectableInterface
{
    use ContainerInjectableTrait;
    /**
     * @var string $db a sample member variable that gets initialised
     */
    private $db = "not active";
    public function initialize() : void
    {
        // Use to initialise member variables.
        $this->db = "active";
        $this->page = $this->di->get("page");
    }
    public function indexActionGet()
    {
        $ipAddress = $this->di->request->getGet('ip') ?? "";
        try {
            $te1 = $this->di->get("weather");
            $data = $te1->requestData($ipAddress);
        } catch (Exception $e) {
            $data["message"] = "Something is wrong with the specified IP address. Please try again.";
        }
        
        $data["specifiedIP"] = $ipAddress;
        return json_encode($data);
    }
}