Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
EnvironmentVariable
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
3 / 3
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 __toPhpCode
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __toString
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; under version 2
7 * of the License (non-upgradable).
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 *
18 * Copyright (c) 2019 (original work) Open Assessment Technologies SA;
19 */
20
21namespace oat\oatbox\service;
22
23use common_Utils as Utils;
24use InvalidArgumentException;
25use oat\oatbox\PhpSerializable;
26
27class EnvironmentVariable implements PhpSerializable
28{
29    /** @var string */
30    private $name;
31
32    public function __construct($name)
33    {
34        if (!is_string($name)) {
35            throw new InvalidArgumentException('Environment variable name must be a string.');
36        }
37
38        $this->name = $name;
39    }
40
41    public function __toPhpCode()
42    {
43        return 'new ' . __CLASS__ . '(' . Utils::toPHPVariableString($this->name) . ')';
44    }
45
46    public function __toString()
47    {
48        return (string) $_ENV[$this->name];
49    }
50}