Test Failed
Push — master ( 0d729d...0caf32 )
by Sebastian
05:03
created

StyleSheet   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 43
rs 10
wmc 4
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A loadStyleSheet() 0 5 1
A loadLocales() 0 5 1
A vendorPath() 0 8 2
1
<?php
2
/**
3
 * citeproc-php
4
 *
5
 * @link        http://github.com/seboettg/citeproc-php for the source repository
6
 * @copyright   Copyright (c) 2016 Sebastian Böttger.
7
 * @license     https://opensource.org/licenses/MIT
8
 */
9
10
namespace Seboettg\CiteProc;
11
12
use Seboettg\CiteProc\Exception\CiteProcException;
13
14
/**
15
 * Class StyleSheet
16
 *
17
 * Helper class for loading CSL styles and CSL locales
18
 *
19
 * @package Seboettg\CiteProc
20
 * @author Sebastian Böttger <[email protected]>
21
 */
22
class StyleSheet
23
{
24
25
    /**
26
     * Loads xml formatted CSL stylesheet of a given stylesheet name, e.g. "american-physiological-society" for
27
     * apa style.
28
     *
29
     * See in styles folder (which is included as git submodule) for all available style sheets
30
     *
31
     * @param string $styleName e.g. "american-physiological-society" for apa
32
     * @return string
33
     */
34
    public static function loadStyleSheet($styleName)
35
    {
36
        $stylesPath = self::vendorPath() . "/citation-style-language/styles/";
37
        return file_get_contents($stylesPath . $styleName . '.csl');
38
    }
39
40
    /**
41
     * Loads xml formatted locales of given language key
42
     *
43
     * @param string $langKey e.g. "en-US", or "de-CH"
44
     * @return string
45
     */
46
    public static function loadLocales($langKey)
47
    {
48
        $localesPath = self::vendorPath() . "/citation-style-language/locales/";
49
        return file_get_contents($localesPath . "locales-" . $langKey . '.xml');
50
    }
51
52
    /**
53
     * @return bool|string
54
     * @throws CiteProcException
55
     */
56
    private static function vendorPath()
57
    {
58
        include_once __DIR__ . '/../../../vendorPath.php';
59
        if (!($vendorPath = vendorPath())) {
60
            throw new CiteProcException('vendor path not found. Use composer to initialize your project');
61
        }
62
        return $vendorPath;
63
    }
64
}