Skip to content

Commit c06f74c

Browse files
committed
Coding Standard
1 parent 3827654 commit c06f74c

9 files changed

+69
-44
lines changed

phpdox.xml.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<collector publiconly="false" backend="parser" encoding="auto">
55
<include mask="*.php" />
66
<exclude mask="" />
7-
<inheritance resolve="true" />
7+
<inheritance resolve="false" />
88
</collector>
99

1010
<generator output="${basedir}/docs">
@@ -33,7 +33,7 @@
3333

3434
<build engine="html" enabled="true" output="html">
3535
<template dir="${phpDox.home}/templates/html" />
36-
<file extension="xhtml" />
36+
<file extension="html" />
3737
</build>
3838
</generator>
3939
</project>

src/Factory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct()
2929
$file = '';
3030
foreach ([
3131
getenv('HOME').'/.config/webhelper/parameters.yml',
32-
__DIR__.'/../app/config/parameters.yml'
32+
__DIR__.'/../app/config/parameters.yml',
3333
] as $file) {
3434
if (is_readable($file)) {
3535
break;
@@ -73,6 +73,7 @@ public function getKnownWebServers()
7373
public function createWebProject($name, $version = '')
7474
{
7575
$name = '';
76+
7677
return new NullWebProject($version);
7778
}
7879
}

src/WebHelper.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
use Composer\Semver\VersionParser;
1515
use Composer\Semver\Comparator;
16-
use JamesRezo\WebHelper\Factory;
17-
use JamesRezo\WebHelper\WebHelperRepository;
1816

1917
/**
2018
* WebHelper.
@@ -91,6 +89,12 @@ public function getServer()
9189
return $this->server;
9290
}
9391

92+
/**
93+
* Sets the PHP Webapp to configure.
94+
*
95+
* @param string $server a PHP Webapp name
96+
* @param string $version a semver-like version
97+
*/
9498
public function setProject($projectname, $version)
9599
{
96100
$factory = new Factory();
@@ -99,6 +103,11 @@ public function setProject($projectname, $version)
99103
return $this;
100104
}
101105

106+
/**
107+
* Gets the PHP Webapp to configure.
108+
*
109+
* @return WebProjectInterface the PHP Webapp instance
110+
*/
102111
public function getProject()
103112
{
104113
return $this->project;
@@ -107,8 +116,9 @@ public function getProject()
107116
/**
108117
* Finds the best template for a web server directive according to its version.
109118
*
110-
* @param string $directive a directive
111-
* @return string the relative path to the template
119+
* @param string $directive a directive
120+
*
121+
* @return string the relative path to the template
112122
*/
113123
public function find($directive)
114124
{
@@ -133,9 +143,10 @@ public function find($directive)
133143
/**
134144
* Outputs a webserver directive.
135145
*
136-
* @param string $twigFile a relative path of a template
137-
* @param array $params parameters
138-
* @return string the directive output
146+
* @param string $twigFile a relative path of a template
147+
* @param array $params parameters
148+
*
149+
* @return string the directive output
139150
*/
140151
public function render($twigFile, array $params = array())
141152
{

src/WebHelperRepository.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
use Symfony\Component\Finder\Finder;
1515
use Composer\Semver\VersionParser;
16-
use \Twig_Loader_Filesystem;
17-
use \Twig_Environment;
16+
use Twig_Loader_Filesystem;
17+
use Twig_Environment;
1818

1919
/**
2020
* WebHelper Repository.
@@ -51,8 +51,9 @@ public function __construct($resDir)
5151
/**
5252
* Initialize the Twig Environment.
5353
*
54-
* @param string $resDir the Path of a Directives Repository
55-
* @return Twig_Environment the Twig Environment
54+
* @param string $resDir the Path of a Directives Repository
55+
*
56+
* @return Twig_Environment the Twig Environment
5657
*/
5758
private function initialize($resDir)
5859
{
@@ -72,8 +73,9 @@ private function initialize($resDir)
7273
/**
7374
* Initialize the structured array of a directives repository.
7475
*
75-
* @param string $resDir the Path of a Directives Repository
76-
* @return array the structured array of a directives repository
76+
* @param string $resDir the Path of a Directives Repository
77+
*
78+
* @return array the structured array of a directives repository
7779
*/
7880
private function memoize($resDir)
7981
{
@@ -122,7 +124,7 @@ public function getTwig()
122124
/**
123125
* Tells if the Repository can be used.
124126
*
125-
* @return boolean true if there are some directives in the Path of a Directives Repository
127+
* @return bool true if there are some directives in the Path of a Directives Repository
126128
*/
127129
public function okGo()
128130
{

src/WebProject/NullWebProject.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public function getParameters()
3333
'aliasname' => $this->getName(),
3434
'documentroot' => getcwd(),
3535
'vhostname' => $this->getName(),
36-
'portnumber' => 80
37-
]
36+
'portnumber' => 80,
37+
],
3838
];
3939
}
4040
}

src/WebProject/WebProject.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
namespace JamesRezo\WebHelper\WebProject;
1313

14-
use Symfony\Component\Process\Process;
15-
1614
/**
1715
* Base class for webproject classes.
1816
*

src/WebServer/WebServer.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,25 @@ public function getSettings($fullPathBinary)
110110
{
111111
$process = new Process($fullPathBinary.$this->detectionParameter);
112112
$process->run();
113+
113114
return $process->getOutput();
114115
}
115116

116117
abstract public function extractVersion($settings = '');
117118

118119
abstract public function extractRootConfigurationFile($settings = '');
119120

121+
abstract public function parseActiveConfig(array $activeConfig = array());
122+
120123
/**
121124
* Finds and return a specific information in a string.
122125
*
123126
* the regexp must contain delimiters.
124127
*
125-
* @param string $regexp a regular expression to find
126-
* @param string $settings a string where to find
127-
* @return string the found value or an empty string
128+
* @param string $regexp a regular expression to find
129+
* @param string $settings a string where to find
130+
*
131+
* @return string the found value or an empty string
128132
*/
129133
protected function match($regexp, $settings)
130134
{
@@ -140,19 +144,25 @@ protected function match($regexp, $settings)
140144
/**
141145
* Loads et cleans a config file.
142146
*
143-
* @param string $file a Configuration file
144-
* @return string the cleaned directives a the config file
147+
* @param string $file a Configuration file
148+
*
149+
* @return array an array of the cleaned directives of a the config per entry
145150
*/
146151
public function getActiveConfig($file = '')
147152
{
148153
$activeConfig = file_get_contents($file);
149154

150-
#Comon to both apache and nginx
151-
#delete commented lines
155+
//Comon to both apache and nginx
156+
//delete commented lines and comments at end of line
152157
$activeConfig = preg_replace('/^\s*#(.+)?/m', '', $activeConfig);
153-
#delete blank lines
158+
$activeConfig = preg_replace('/^#(.+)$/m', '', $activeConfig);
159+
//delete blank lines
154160
$activeConfig = preg_replace('/^\h*\v+/m', '', $activeConfig);
161+
//convert dos to unix format
162+
$activeConfig = str_replace("\r\n", "\n", $activeConfig);
163+
//convert old macos to unix format
164+
$activeConfig = str_replace("\r", "\n", $activeConfig);
155165

156-
return $activeConfig;
166+
return explode("\n", $activeConfig);
157167
}
158168
}

tests/AnalyzeCommandTest.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,27 @@ public function dataExecute()
2323
$data = [];
2424

2525
$data['Null'] = [
26-
'Web Server "test" unknown.'."\n",
26+
'Web Server "test" unknown.',
2727
'test',
28-
''
28+
'',
2929
];
3030

3131
$data['config file does not exist'] = [
32-
'Configuration file "nginx.conf" does not exist.'."\n",
32+
'Configuration file "nginx.conf" does not exist.',
3333
'nginx',
34-
'nginx.conf'
34+
'nginx.conf',
3535
];
3636

3737
$data['nginx'] = [
3838
'',
3939
'nginx',
40-
realpath(__DIR__.'/dummyfilesystem/etc/nginx.conf')
40+
realpath(__DIR__.'/dummyfilesystem/etc/nginx.conf'),
4141
];
4242

4343
$data['Apache 2.4'] = [
4444
'',
4545
'apache:2.4.18',
46-
realpath(__DIR__.'/dummyfilesystem/etc/httpd.conf')
46+
realpath(__DIR__.'/dummyfilesystem/etc/httpd.conf'),
4747
];
4848

4949
return $data;
@@ -60,12 +60,15 @@ public function testExecute($expected, $webserver, $configfile)
6060
$command = $application->find('analyze');
6161
$commandTester = new CommandTester($command);
6262
$commandTester->execute(array(
63-
'command' => $command->getName(),
63+
'command' => $command->getName(),
6464
'webserver' => $webserver,
65-
'configfile' => $configfile
65+
'configfile' => $configfile,
6666
));
6767

68-
$output = $commandTester->getDisplay();
69-
$this->assertEquals($expected, $output);
68+
if ($expected) {
69+
$this->assertContains($expected, $commandTester->getDisplay());
70+
} else {
71+
$this->assertEquals($expected, $commandTester->getDisplay());
72+
}
7073
}
7174
}

tests/WebHelperRepositoryTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ public function dataOkGo()
2222

2323
$data['unset'] = [
2424
false,
25-
''
25+
'',
2626
];
2727

2828
$data['finder can\'t find resDir'] = [
2929
false,
30-
'doesntexist'
30+
'doesntexist',
3131
];
3232

3333
$data['twig can\'t find resDir'] = [
3434
false,
35-
'doesntexist'
35+
'doesntexist',
3636
];
3737

3838
$data['resDir does exist'] = [
3939
true,
40-
__DIR__ . '/dummyrepo'
40+
__DIR__.'/dummyrepo',
4141
];
4242

4343
return $data;

0 commit comments

Comments
 (0)