Completed
Pull Request — master (#145)
by
unknown
03:35
created

ApiKeys::env()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
ccs 1
cts 1
cp 1
rs 9.4285
cc 3
eloc 8
nc 2
nop 2
crap 3
1
<?php
2
namespace SEOstats\Config;
3
4
/**
5
 * Configuration constants for the SEOstats library.
6
 *
7
 * @package    SEOstats
8
 * @author     Stephan Schmitz <[email protected]>
9
 * @copyright  Copyright (c) 2010 - present Stephan Schmitz
10
 * @license    http://eyecatchup.mit-license.org/  MIT License
11
 * @updated    2013/12/11
12
 */
13
14
/**
15
 * Client API keys
16
 * @package    SEOstats
17
 */
18
class ApiKeys
19
{
20
    // To acquire an API key, visit Google's APIs Console here:
21
    //      https://code.google.com/apis/console
22
    // In the Services pane, activate the "PageSpeed Insights API" (not the service!).
23
    // Next, go to the API Access pane. The API key is near the bottom of that pane,
24
    // in the section titled "Simple API Access.".
25
    const GOOGLE_SIMPLE_API_ACCESS_KEY = '';
26
27
    // To acquire a Mozscape (f.k.a. SEOmoz) API key, visit:
28
    //      https://moz.com/products/api/keys
29
    const MOZSCAPE_ACCESS_ID  = '';
30
    const MOZSCAPE_SECRET_KEY = '';
31
32
    // To acquire a SISTRIX API key, visit:
33
    //      http://www.sistrix.de
34
    const SISTRIX_API_ACCESS_KEY = '';
35
    //
36 1
    public static function env($config, $default)
37
    {
38
        $dotenv = new \Dotenv\Dotenv(__DIR__."/../../../../../");
39
        $dotenv->load();
40
        $config_value = getenv($config);
41
        if(is_string($config_value) && (strlen(trim($config_value)) > 0)) {
42
            return $config_value;
43
        } else {
44
            return $default;
45
        }
46
    }
47
48
    public static function getGoogleSimpleApiAccessKey() {
49
        return self::env('GOOGLE_SIMPLE_API_ACCESS_KEY', self::GOOGLE_SIMPLE_API_ACCESS_KEY);
50
    }
51
52
    public static function getMozscapeAccessId() {
53
        return self::env('MOZSCAPE_ACCESS_ID', self::MOZSCAPE_ACCESS_ID);
54
    }
55
56
    public static function getMozscapeSecretKey()
57
    {
58
        return self::env('MOZSCAPE_SECRET_KEY', self::MOZSCAPE_SECRET_KEY);
59
    }
60
61
    public static function getSistrixApiAccessKey()
62
    {
63
        return self::env('SISTRIX_API_ACCESS_KEY', self::SISTRIX_API_ACCESS_KEY);
64
    }
65
}
66