Skip to content

Commit 3c8fa6d

Browse files
committed
Added scrutinizer configuration;
CS fixes.
1 parent e5abd1c commit 3c8fa6d

File tree

10 files changed

+255
-210
lines changed

10 files changed

+255
-210
lines changed

.scrutinizer.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
imports:
2+
- php
3+
inherit: true
4+
tools:
5+
php_sim: false
6+
php_cpd: true
7+
php_code_sniffer:
8+
config:
9+
standard: PEAR

extrasetup.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
<?php
2+
3+
/**
4+
* extrasetup.php for PEAR2_Cache_SHM.
5+
*
6+
* PHP version 5.3
7+
*
8+
* @category Caching
9+
* @package PEAR2_Cache_SHM
10+
* @author Vasil Rangelov <[email protected]>
11+
* @copyright 2011 Vasil Rangelov
12+
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
13+
* @version GIT: $Id$
14+
* @link http://pear2.php.net/PEAR2_Cache_SHM
15+
*/
16+
217
$extrafiles = array();
318
$phpDir = Pyrus\Config::current()->php_dir . DIRECTORY_SEPARATOR;
419
$packages = array('PEAR2/Autoload');

packagexmlsetup.php

Lines changed: 135 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,168 +1,163 @@
11
<?php
2+
3+
/**
4+
* packagexmlsetup.php for PEAR2_Cache_SHM.
5+
*
6+
* PHP version 5.3
7+
*
8+
* @category Caching
9+
* @package PEAR2_Cache_SHM
10+
* @author Vasil Rangelov <[email protected]>
11+
* @copyright 2011 Vasil Rangelov
12+
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
13+
* @version GIT: $Id$
14+
* @link http://pear2.php.net/PEAR2_Cache_SHM
15+
*/
16+
17+
/**
18+
* References the package in $package and/or $compatible.
19+
*/
220
use Pyrus\Developer\PackageFile\v2;
321

22+
/**
23+
* Configuration array.
24+
*
25+
* Each key is the task.
26+
*
27+
* The task "replace" uses an array where the key is the value to be searched
28+
* for, and the value is an array of additional attributes for the task, which
29+
* normally contain at least "type" (pear-config/package-info) and "to", which
30+
* specifies the value to replace it with.
31+
*
32+
* The task "eol" uses an array where the key is a filename pattern to be
33+
* matched, and the value is the target platform's EOL to be used for those
34+
* file names (windows/unix).
35+
*
36+
* Unrecognized tasks are ignored.
37+
*
38+
* @var array
39+
*/
40+
$config = array(
41+
'replace' => array(
42+
'../src' => array(
43+
'type' => 'pear-config',
44+
'to' => 'php_dir'
45+
),
46+
'GIT: $Id$' => array(
47+
'type' => 'package-info',
48+
'to' => 'version'
49+
)
50+
),
51+
'eol' => array(
52+
'*.bat' => 'windows'
53+
)
54+
);
55+
56+
if (!isset($package)) {
57+
die('This file must be executed via "pyrus.phar make".');
58+
}
59+
460
$packageGen = function (
61+
array $config,
562
v2 $package,
663
v2 $compatible = null
764
) {
8-
$srcDirTask = array(
9-
'tasks:replace' => array(
10-
array(
11-
'attribs' => array(
12-
'from' => '../src',
13-
'to' => 'php_dir',
14-
'type' => 'pear-config'
15-
)
16-
)
17-
)
18-
);
19-
20-
$srcFileTasks = array(
21-
'tasks:replace' => array(
22-
array(
23-
'attribs' => array(
24-
'from' => '~~summary~~',
25-
'to' => 'summary',
26-
'type' => 'package-info'
27-
)
28-
),
29-
array(
30-
'attribs' => array(
31-
'from' => '~~description~~',
32-
'to' => 'description',
33-
'type' => 'package-info'
34-
)
35-
),
36-
array(
37-
'attribs' => array(
38-
'from' => 'GIT: $Id$',
39-
'to' => 'version',
40-
'type' => 'package-info'
41-
)
42-
)
43-
)
44-
);
4565

46-
$package->files['tests/bootstrap.php'] = array_merge_recursive(
47-
$package->files['tests/bootstrap.php']->getArrayCopy(),
48-
$srcDirTask
49-
);
66+
$tasksNs = $package->getTasksNs();
67+
$cTasksNs = $compatible ? $compatible->getTasksNs() : '';
5068

51-
$package->files['docs/phpdoc.dist.xml'] = array_merge_recursive(
52-
$package->files['docs/phpdoc.dist.xml']->getArrayCopy(),
53-
$srcDirTask
54-
);
55-
$package->files['docs/apigen.neon'] = array_merge_recursive(
56-
$package->files['docs/apigen.neon']->getArrayCopy(),
57-
$srcDirTask
58-
);
69+
$oldCwd = getcwd();
70+
chdir(__DIR__);
71+
foreach (new RecursiveIteratorIterator(
72+
new RecursiveDirectoryIterator(
73+
'.',
74+
RecursiveDirectoryIterator::UNIX_PATHS
75+
| RecursiveDirectoryIterator::SKIP_DOTS
76+
),
77+
RecursiveIteratorIterator::LEAVES_ONLY
78+
) as $path) {
79+
$filename = substr($path->getPathname(), 2);
80+
$cFilename = str_replace('src/', 'php/', $filename);
5981

60-
$package->files['docs/doxygen.ini'] = array_merge_recursive(
61-
$package->files['docs/doxygen.ini']->getArrayCopy(),
62-
$srcDirTask,
63-
array(
64-
'tasks:replace' => array(
65-
array(
66-
'attribs' => array(
67-
'from' => 'GIT: $Id$',
68-
'to' => 'version',
69-
'type' => 'package-info'
82+
if (isset($package->files[$filename])) {
83+
$parsedFilename = pathinfo($filename);
84+
$as = (strpos($filename, 'examples/') === 0)
85+
? $filename
86+
: substr($filename, strpos($filename, '/') + 1);
87+
if (strpos($filename, 'scripts/') === 0) {
88+
if (isset($parsedFilename['extension'])
89+
&& 'php' === $parsedFilename['extension']
90+
&& !is_file(
91+
$parsedFilename['dirname'] . '/' .
92+
$parsedFilename['filename']
7093
)
71-
)
72-
)
73-
)
74-
);
75-
$hasCompatible = null !== $compatible;
76-
if ($hasCompatible) {
77-
$compatible->license = $package->license;
78-
$compatible->files[
79-
"test/{$package->channel}/{$package->name}/bootstrap.php"
80-
] = array_merge_recursive(
81-
$compatible->files[
82-
"test/{$package->channel}/{$package->name}/bootstrap.php"
83-
]->getArrayCopy(),
84-
$srcDirTask
85-
);
86-
87-
$compatible->files[
88-
"doc/{$package->channel}/{$package->name}/phpdoc.dist.xml"
89-
] = array_merge_recursive(
90-
$compatible->files[
91-
"doc/{$package->channel}/{$package->name}/phpdoc.dist.xml"
92-
]->getArrayCopy(),
93-
$srcDirTask
94-
);
94+
&& is_file(
95+
$parsedFilename['dirname'] . '/' .
96+
$parsedFilename['filename'] . '.bat'
97+
)
98+
) {
99+
$as = substr($as, 0, -4);
100+
}
101+
}
102+
$package->getReleaseToInstall('php')->installAs($filename, $as);
95103

96-
$compatible->files["doc/{$package->channel}/{$package->name}/doxygen.ini"]
97-
= array_merge_recursive(
98-
$compatible->files[
99-
"doc/{$package->channel}/{$package->name}/doxygen.ini"
100-
]->getArrayCopy(),
101-
$srcDirTask,
102-
array(
103-
'tasks:replace' => array(
104+
$contents = file_get_contents($filename);
105+
foreach ($config['replace'] as $from => $attribs) {
106+
if (strpos($contents, $from) !== false) {
107+
$attribs['from'] = $from;
108+
$package->files[$filename] = array_merge_recursive(
109+
$package->files[$filename]->getArrayCopy(),
104110
array(
105-
'attribs' => array(
106-
'from' => 'GIT: $Id$',
107-
'to' => 'version',
108-
'type' => 'package-info'
111+
"{$tasksNs}:replace" => array(
112+
array(
113+
'attribs' => $attribs
114+
)
109115
)
110116
)
111-
)
112-
)
113-
);
114-
}
117+
);
115118

116-
$oldCwd = getcwd();
117-
chdir(__DIR__);
118-
foreach (
119-
new RecursiveIteratorIterator(
120-
new RecursiveDirectoryIterator(
121-
'src',
122-
RecursiveDirectoryIterator::UNIX_PATHS
123-
| RecursiveDirectoryIterator::SKIP_DOTS
124-
),
125-
RecursiveIteratorIterator::LEAVES_ONLY
126-
) as $path) {
127-
$filename = $path->getPathname();
128-
129-
$package->files[$filename] = array_merge_recursive(
130-
$package->files[$filename]->getArrayCopy(),
131-
$srcFileTasks
132-
);
133-
134-
if ($hasCompatible) {
135-
$compatibleFilename = str_replace('src/', 'php/', $filename);
136-
$compatible->files[$compatibleFilename] = array_merge_recursive(
137-
$compatible->files[$compatibleFilename]->getArrayCopy(),
138-
$srcFileTasks
139-
);
140-
}
141-
}
119+
if ($compatible) {
120+
$compatible->files[$cFilename] = array_merge_recursive(
121+
$compatible->files[$cFilename]->getArrayCopy(),
122+
array(
123+
"{$cTasksNs}:replace" => array(
124+
array(
125+
'attribs' => $attribs
126+
)
127+
)
128+
)
129+
);
130+
}
131+
}
132+
}
142133

143-
foreach (
144-
new RecursiveIteratorIterator(
145-
new RecursiveDirectoryIterator(
146-
'.',
147-
RecursiveDirectoryIterator::UNIX_PATHS
148-
| RecursiveDirectoryIterator::SKIP_DOTS
149-
),
150-
RecursiveIteratorIterator::LEAVES_ONLY
151-
) as $path) {
152-
$filename = substr($path->getPathname(), 2);
134+
foreach ($config['eol'] as $pattern => $platform) {
135+
if (fnmatch($pattern, $filename)) {
136+
$package->files[$filename] = array_merge_recursive(
137+
$package->files[$filename]->getArrayCopy(),
138+
array(
139+
"{$tasksNs}:{$platform}eol" => array()
140+
)
141+
);
153142

154-
if (isset($package->files[$filename])) {
155-
$as = (strpos($filename, 'examples') === 0)
156-
? $filename
157-
: substr($filename, strpos($filename, '/') + 1);
158-
$package->getReleaseToInstall('php')->installAs($filename, $as);
143+
if ($compatible) {
144+
$compatible->files[$cFilename] = array_merge_recursive(
145+
$compatible->files[$cFilename]->getArrayCopy(),
146+
array(
147+
"{$cTasksNs}:{$platform}eol" => array()
148+
)
149+
);
150+
}
151+
}
152+
}
159153
}
160154
}
161155
chdir($oldCwd);
162156
return array($package, $compatible);
163157
};
164158

165159
list($package, $compatible) = $packageGen(
160+
$config,
166161
$package,
167162
isset($compatible) ? $compatible : null
168163
);

src/PEAR2/Cache/SHM.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,25 @@
77
*
88
* PHP version 5
99
*
10-
* @category Cache
10+
* @category Caching
1111
* @package PEAR2_Cache_SHM
1212
* @author Vasil Rangelov <[email protected]>
1313
* @copyright 2011 Vasil Rangelov
1414
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
1515
* @version GIT: $Id$
1616
* @link http://pear2.php.net/PEAR2_Cache_SHM
1717
*/
18+
1819
/**
1920
* The namespace declaration.
2021
*/
2122
namespace PEAR2\Cache;
2223

24+
/**
25+
* Used as a catch-all for adapter initialization.
26+
*/
27+
use Exception as E;
28+
2329
/**
2430
* Main class for this package.
2531
*
@@ -54,7 +60,8 @@ final public static function factory($persistentId)
5460
foreach (self::$_adapters as $adapter) {
5561
try {
5662
return new $adapter($persistentId);
57-
} catch (\Exception $e) {
63+
} catch (E $e) {
64+
//In case of a runtime error, try to fallback to other adapters.
5865
}
5966
}
6067
throw new SHM\InvalidArgumentException(

src/PEAR2/Cache/SHM/Adapter/APC.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* PHP version 5
99
*
10-
* @category Cache
10+
* @category Caching
1111
* @package PEAR2_Cache_SHM
1212
* @author Vasil Rangelov <[email protected]>
1313
* @copyright 2011 Vasil Rangelov

src/PEAR2/Cache/SHM/Adapter/Placebo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* PHP version 5
99
*
10-
* @category Cache
10+
* @category Caching
1111
* @package PEAR2_Cache_SHM
1212
* @author Vasil Rangelov <[email protected]>
1313
* @copyright 2011 Vasil Rangelov

src/PEAR2/Cache/SHM/Adapter/Wincache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* PHP version 5
99
*
10-
* @category Cache
10+
* @category Caching
1111
* @package PEAR2_Cache_SHM
1212
* @author Vasil Rangelov <[email protected]>
1313
* @copyright 2011 Vasil Rangelov

0 commit comments

Comments
 (0)