Skip to content

Commit 290971f

Browse files
committed
split assertions to traits
bump required php version remove php 5.3 travis add abstract __callStatic move docblocks back move traits to namespace wip const links generator add upgrade notes split assertions to traits bump required php version add abstract __callStatic remove php 5.3 travis move docblocks back move traits to namespace
1 parent e28547c commit 290971f

16 files changed

+2554
-2271
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ git:
55

66
matrix:
77
include:
8-
- php: 5.3
98
- php: 5.4
109
- php: 5.5
1110
- php: 5.6

CONTRIBUTING.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ Thanks for contributing to assert! Just follow these single guidelines:
44

55
- You must use [feature / topic branches](https://git-scm.com/book/en/v2/Git-Branching-Branching-Workflows) to ease the merge of contributions.
66
- Coding standard compliance must be ensured before committing or opening pull requests by running `composer assert:cs-fix` or `composer assert:cs-lint` in the root directory of this repository.
7-
- After adding new assertions regenerate the [README.md](README.md) and the docblocks by running `composer assert:generate-docs` on the command line.
7+
- After adding new assertions regenerate the [README.md](README.md) and the docblocks by running `composer assert:generate` on the command line.
88
- After adding new non release relevant artifacts you must ensure they are export ignored in the [.gitattributes](.gitattributes) file.
9-

UPGRADE_3.0.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Upgrade notes
2+
3+
Dropped php 5.3 support.
4+
5+
Error code constants in `Assertion` class are now deprecated and will be removed in 4.0 release.
6+
Preferred way is to use constants from `Assert\Assertion` namespace as follows:
7+
```
8+
# before 3.0:
9+
\Assert\Assertion::INVALID_JSON_STRING
10+
11+
# 3.0:
12+
\Assert\Assertion\INVALID_JSON_STRING
13+
```
14+
So you need to replace `::` with `\` in before constant name.

bin/generate_method_docs.php renamed to bin/generate_code.php

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private function gatherAssertions()
102102
return \array_filter(
103103
$reflClass->getMethods(ReflectionMethod::IS_STATIC),
104104
function (ReflectionMethod $reflMethod) {
105-
if ($reflMethod->isProtected()) {
105+
if (!$reflMethod->isPublic()) {
106106
return false;
107107
}
108108

@@ -140,6 +140,14 @@ private function generateFile($phpFile, $lines, $fileType)
140140
$fileContent
141141
);
142142
break;
143+
144+
case 'const':
145+
$fileContent = \preg_replace(
146+
'`// constants linked for BC(?:\s*const [A-Z_\d\\\]+ = [A-Z_\d\\\]+;)+`sim',
147+
\sprintf("// constants linked for BC\n %s", \trim(\implode("\n", $lines))),
148+
$fileContent
149+
);
150+
break;
143151
}
144152

145153
$writtenBytes = \file_put_contents($phpFile, $fileContent);
@@ -213,11 +221,49 @@ function (ReflectionMethod $reflMethod) {
213221
}
214222
);
215223
}
224+
225+
public function generateConstants()
226+
{
227+
$phpFile = __DIR__.'/../lib/Assert/Assertion.php';
228+
$constants = $this->gatherConstants();
229+
230+
$this->generateFile($phpFile, $constants, 'const');
231+
}
232+
233+
/**
234+
* @return string[]
235+
*/
236+
private function gatherConstants()
237+
{
238+
$namespace = 'Assert\\Assertion\\';
239+
240+
// load class to load all traits and fill namespace with constants
241+
/* @noinspection ExceptionsAnnotatingAndHandlingInspection */
242+
\Assert\Assertion::string($namespace);
243+
244+
$constants = \get_defined_constants(true);
245+
if (!isset($constants['user'])) {
246+
return [];
247+
}
248+
249+
$constants = \array_keys($constants['user']);
250+
251+
$namespaceConstants = \array_filter($constants, function ($name) use ($namespace) {
252+
return 0 === \strpos($name, $namespace);
253+
});
254+
255+
return \array_map(function ($name) use ($namespace) {
256+
$const = \substr($name, \strlen($namespace));
257+
258+
return ' const ' . $const . ' = Assertion\\' . $const . ';';
259+
}, $namespaceConstants);
260+
}
216261
}
217262

218263
require_once __DIR__.'/../vendor/autoload.php';
219264

220265
$generator = new MethodDocGenerator();
266+
$generator->generateConstants();
221267
$generator->generateAssertionDocs();
222268
$generator->generateChainDocs();
223269
$generator->generateLazyAssertionDocs();

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"sort-packages": true
2424
},
2525
"require": {
26-
"php": ">=5.3",
26+
"php": ">=5.4",
2727
"ext-mbstring": "*"
2828
},
2929
"require-dev": {
@@ -47,7 +47,7 @@
4747
]
4848
},
4949
"scripts": {
50-
"assert:generate-docs": "php bin/generate_method_docs.php",
50+
"assert:generate": "php bin/generate_code.php",
5151
"assert:cs-lint": "php-cs-fixer fix --diff -vvv --dry-run",
5252
"assert:cs-fix": "php-cs-fixer fix . -vvv || true"
5353
}

0 commit comments

Comments
 (0)