Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
27 / 27
100.00% covered (success)
100.00%
8 / 8
CRAP
100.00% covered (success)
100.00%
1 / 1
InterfaceGenerator
100.00% covered (success)
100.00%
27 / 27
100.00% covered (success)
100.00%
8 / 8
15
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 setParent
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getParent
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasParent
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 render
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
6
 formatConstants
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 formatMethods
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 __toString
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * Pop PHP Framework (http://www.popphp.org/)
4 *
5 * @link       https://github.com/popphp/popphp-framework
6 * @author     Nick Sagona, III <dev@nolainteractive.com>
7 * @copyright  Copyright (c) 2009-2023 NOLA Interactive, LLC. (http://www.nolainteractive.com)
8 * @license    http://www.popphp.org/license     New BSD License
9 */
10
11/**
12 * @namespace
13 */
14namespace Pop\Code\Generator;
15
16/**
17 * Interface generator class
18 *
19 * @category   Pop
20 * @package    Pop\Code
21 * @author     Nick Sagona, III <dev@nolainteractive.com>
22 * @copyright  Copyright (c) 2009-2023 NOLA Interactive, LLC. (http://www.nolainteractive.com)
23 * @license    http://www.popphp.org/license     New BSD License
24 * @version    4.1.0
25 */
26class InterfaceGenerator extends AbstractClassGenerator
27{
28
29    /**
30     * Parent interfaces that are extended
31     * @var string
32     */
33    protected $parent = null;
34
35    /**
36     * Constructor
37     *
38     * Instantiate the interface generator object
39     *
40     * @param  string  $name
41     * @param  string  $parent
42     */
43    public function __construct($name, $parent = null)
44    {
45        $this->setName($name);
46        $this->setParent($parent);
47    }
48
49    /**
50     * Set the interface parent
51     *
52     * @param  string $parent
53     * @return InterfaceGenerator
54     */
55    public function setParent($parent = null)
56    {
57        $this->parent = $parent;
58        return $this;
59    }
60
61    /**
62     * Get the interface parent
63     *
64     * @return string
65     */
66    public function getParent()
67    {
68        return $this->parent;
69    }
70
71    /**
72     * Has parent
73     *
74     * @return boolean
75     */
76    public function hasParent()
77    {
78        return (null !== $this->parent);
79    }
80
81    /**
82     * Render interface
83     *
84     * @return string
85     */
86    public function render()
87    {
88        $this->output  = (null !== $this->namespace) ? $this->namespace->render() . PHP_EOL : null;
89        $this->output .= (null !== $this->docblock) ? $this->docblock->render() : null;
90        $this->output .= 'interface ' . $this->name;
91
92        if (null !== $this->parent) {
93            $this->output .= ' extends ' . $this->parent;
94        }
95
96        $this->output .= PHP_EOL . '{' . PHP_EOL;
97
98        if ($this->hasConstants()) {
99            $this->output .= $this->formatConstants();
100        }
101        if ($this->hasMethods()) {
102            $this->output .= $this->formatMethods();
103        }
104
105        $this->output .= PHP_EOL . '}' . PHP_EOL;
106
107        return $this->output;
108    }
109
110    /**
111     * Format the constants
112     *
113     * @return string
114     */
115    protected function formatConstants()
116    {
117        $constants = null;
118
119        foreach ($this->constants as $constant) {
120            $constants .= $constant->render() . PHP_EOL;
121        }
122
123        return $constants;
124    }
125
126    /**
127     * Format the methods
128     *
129     * @return string
130     */
131    protected function formatMethods()
132    {
133        $methods = null;
134
135        foreach ($this->methods as $method) {
136            $methods .= $method->render() . PHP_EOL;
137        }
138
139        return $methods;
140    }
141
142    /**
143     * Print interface
144     *
145     * @return string
146     */
147    public function __toString()
148    {
149        return $this->render();
150    }
151
152}