Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ git:

matrix:
include:
- php: 5.3
- php: 5.4
- php: 5.5
- php: 5.6
Expand Down
3 changes: 1 addition & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ Thanks for contributing to assert! Just follow these single guidelines:

- You must use [feature / topic branches](https://git-scm.com/book/en/v2/Git-Branching-Branching-Workflows) to ease the merge of contributions.
- 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.
- After adding new assertions regenerate the [README.md](README.md) and the docblocks by running `composer assert:generate-docs` on the command line.
- After adding new assertions regenerate the [README.md](README.md) and the docblocks by running `composer assert:generate` on the command line.
- After adding new non release relevant artifacts you must ensure they are export ignored in the [.gitattributes](.gitattributes) file.

16 changes: 16 additions & 0 deletions UPGRADE_3.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Upgrade notes

Dropped php 5.3 support.

Error code constants in `Assertion` class are now deprecated and will be removed in 4.0 release.
Preferred way is to use constants from `Assert\Assertion` namespace as follows:
```
# before 3.0:
\Assert\Assertion::INVALID_JSON_STRING

# 3.0:
\Assert\Assertion\INVALID_JSON_STRING
```
So you need to replace `::` with `\` before constant name.

These can be easily done with following regular expression search and replace: search for `Assertion::([A-Z_\d]+)` and replace with `Assertion\\$1`.
54 changes: 53 additions & 1 deletion bin/generate_method_docs.php → bin/generate_code.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private function gatherAssertions()
return \array_filter(
$reflClass->getMethods(ReflectionMethod::IS_STATIC),
function (ReflectionMethod $reflMethod) {
if ($reflMethod->isProtected()) {
if (!$reflMethod->isPublic()) {
return false;
}

Expand Down Expand Up @@ -140,6 +140,14 @@ private function generateFile($phpFile, $lines, $fileType)
$fileContent
);
break;

case 'const':
$fileContent = \preg_replace(
'`// constants linked for BC\n(.*)// end constants linked for BC\n`sim',
\sprintf("// constants linked for BC\n %s\n // end constants linked for BC\n", \trim(\implode("\n", $lines))),
$fileContent
);
break;
}

$writtenBytes = \file_put_contents($phpFile, $fileContent);
Expand Down Expand Up @@ -213,11 +221,55 @@ function (ReflectionMethod $reflMethod) {
}
);
}

public function generateConstants()
{
$phpFile = __DIR__.'/../lib/Assert/Assertion.php';
$constants = $this->gatherConstants();

$this->generateFile($phpFile, $constants, 'const');
}

/**
* @return string[]
*/
private function gatherConstants()
{
$namespace = 'Assert\\Assertion\\';

// load class to load all traits and fill namespace with constants
/* @noinspection ExceptionsAnnotatingAndHandlingInspection */
\Assert\Assertion::string($namespace);

$constants = \get_defined_constants(true);
if (!isset($constants['user'])) {
return [];
}

$constants = \array_keys($constants['user']);

$namespaceConstants = \array_filter($constants, function ($name) use ($namespace) {
return 0 === \strpos($name, $namespace);
});

return \array_map(function ($name) use ($namespace) {
$const = \substr($name, \strlen($namespace));

return <<<CONST
/**
* @deprecated
* @see Assertion\\{$const}
*/
const {$const} = Assertion\\{$const};
CONST;
}, $namespaceConstants);
}
}

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

$generator = new MethodDocGenerator();
$generator->generateConstants();
$generator->generateAssertionDocs();
$generator->generateChainDocs();
$generator->generateLazyAssertionDocs();
Expand Down
4 changes: 2 additions & 2 deletions bin/travis/lint-docs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
set -e
composer assert:generate-docs
composer assert:generate
UNCOMMITED_FILES=$(git status -s | wc -l)
if [[ $UNCOMMITED_FILES -ne 0 ]]; then
echo "Please run composer assert:generate-docs and commit the changes";
echo "Please run composer assert:generate and commit the changes";
exit 1;
fi
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"sort-packages": true
},
"require": {
"php": ">=5.3",
"php": ">=5.4",
"ext-mbstring": "*"
},
"require-dev": {
Expand All @@ -35,7 +35,8 @@
"Assert\\": "lib/Assert"
},
"files": [
"lib/Assert/functions.php"
"lib/Assert/functions.php",
"lib/Assert/Assertion.php"
]
},
"autoload-dev": {
Expand All @@ -47,7 +48,7 @@
]
},
"scripts": {
"assert:generate-docs": "php bin/generate_method_docs.php",
"assert:generate": "php bin/generate_code.php",
"assert:cs-lint": "php-cs-fixer fix --diff -vvv --dry-run",
"assert:cs-fix": "php-cs-fixer fix . -vvv || true"
}
Expand Down
Loading