1: <?php
2:
3: namespace Alpha\Controller;
4:
5: use Alpha\Util\Logging\Logger;
6: use Alpha\Util\Code\Metric\Inspector;
7: use Alpha\Util\Http\Response;
8: use Alpha\Util\Config\ConfigProvider;
9: use Alpha\View\View;
10:
11: /**
12: * Controller used to display the software metrics for the application.
13: *
14: * @since 1.0
15: *
16: * @author John Collins <dev@alphaframework.org>
17: * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
18: * @copyright Copyright (c) 2015, John Collins (founder of Alpha Framework).
19: * All rights reserved.
20: *
21: * <pre>
22: * Redistribution and use in source and binary forms, with or
23: * without modification, are permitted provided that the
24: * following conditions are met:
25: *
26: * * Redistributions of source code must retain the above
27: * copyright notice, this list of conditions and the
28: * following disclaimer.
29: * * Redistributions in binary form must reproduce the above
30: * copyright notice, this list of conditions and the
31: * following disclaimer in the documentation and/or other
32: * materials provided with the distribution.
33: * * Neither the name of the Alpha Framework nor the names
34: * of its contributors may be used to endorse or promote
35: * products derived from this software without specific
36: * prior written permission.
37: *
38: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
39: * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
40: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
41: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
42: * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
43: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
48: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
49: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
50: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51: * </pre>
52: */
53: class MetricController extends Controller implements ControllerInterface
54: {
55: /**
56: * Trace logger.
57: *
58: * @var Alpha\Util\Logging\Logger
59: *
60: * @since 1.0
61: */
62: private static $logger = null;
63:
64: /**
65: * The constructor.
66: *
67: * @since 1.0
68: */
69: public function __construct()
70: {
71: self::$logger = new Logger('MetricController');
72: self::$logger->debug('>>__construct()');
73:
74: // ensure that the super class constructor is called, indicating the rights group
75: parent::__construct('Admin');
76:
77: $this->setTitle('Application Metrics');
78:
79: self::$logger->debug('<<__construct');
80: }
81:
82: /**
83: * Handle GET requests.
84: *
85: * @param Alpha\Util\Http\Request $request
86: *
87: * @return Alpha\Util\Http\Response
88: *
89: * @since 1.0
90: */
91: public function doGET($request)
92: {
93: self::$logger->debug('>>doGET($request=['.var_export($request, true).'])');
94:
95: $config = ConfigProvider::getInstance();
96:
97: $body = View::displayPageHead($this);
98:
99: if ($request->getParam('dir')) {
100: $dir = $request->getParam('dir');
101: } else {
102: $dir = $config->get('app.root');
103: }
104:
105: $metrics = new Inspector($dir);
106: $metrics->calculateLOC();
107: $body .= $metrics->resultsToHTML();
108:
109: $body .= View::displayPageFoot($this);
110:
111: self::$logger->debug('<<doGET');
112:
113: return new Response(200, $body, array('Content-Type' => 'text/html'));
114: }
115: }
116: