PK _QK8%
LICENSE.mdnu ٘ Copyright (c) 2020 Laminas Project a Series of LF Projects, LLC.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of Laminas Foundation nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
PK _QF[ [ COPYRIGHT.mdnu ٘ Copyright (c) 2020 Laminas Project a Series of LF Projects, LLC. (https://getlaminas.org/)
PK _Q .travis.ymlnu ٘ language: php
cache:
directories:
- $HOME/.composer/cache
env:
global:
- COMPOSER_ARGS="--no-interaction --ignore-platform-reqs"
matrix:
fast_finish: true
include:
- php: 7.1
env:
- DEPS=lowest
- php: 7.1
env:
- DEPS=latest
- php: 7.2
env:
- DEPS=lowest
- php: 7.2
env:
- DEPS=latest
- php: 7.3
env:
- DEPS=lowest
- php: 7.3
env:
- DEPS=latest
- php: 7.4
env:
- DEPS=lowest
- php: 7.4
env:
- DEPS=latest
- php: nightly
env:
- DEPS=lowest
- php: nightly
env:
- DEPS=latest
addons:
apt:
packages:
- libxml2-utils
before_install:
- phpenv config-rm xdebug.ini || return 0
install:
- travis_retry composer install $COMPOSER_ARGS
- if [[ $DEPS == 'latest' ]]; then travis_retry composer update $COMPOSER_ARGS ; fi
- if [[ $DEPS == 'lowest' ]]; then travis_retry composer update --prefer-lowest --prefer-stable $COMPOSER_ARGS ; fi
- stty cols 120 && composer show
script:
- xmllint --noout --schema vendor/squizlabs/php_codesniffer/phpcs.xsd src/LaminasCodingStandard/ruleset.xml
- composer check
notifications:
email: false
PK _QX
\ README.mdnu ٘ # laminas-coding-standard
[![Build Status](https://travis-ci.com/laminas/laminas-coding-standard.svg?branch=master)](https://travis-ci.com/laminas/laminas-coding-standard)
The coding standard ruleset for Laminas components.
This specification extends and expands [PSR-12](https://github.com/php-fig/fig-standards/blob/master/proposed/extended-coding-style-guide.md),
the extended coding style guide and requires adherence to [PSR-1](https://www.php-fig.org/psr/psr-1),
the basic coding standard. These are minimal specifications and don't address all factors, including things like:
- whitespace around operators
- alignment of array keys and operators
- alignment of object operations
- how to format multi-line conditionals
- what and what not to import, and how
- etc.
Contributors have different coding styles and so do the maintainers. During code reviews there are regularly
discussions about spaces and alignments, where and when was said that a function needs to be imported. And
that's where this coding standard comes in: To have internal consistency in a component and between components.
## Installation
1. Install the module via composer by running:
```bash
$ composer require --dev laminas/laminas-coding-standard
```
2. Add composer scripts into your `composer.json`:
```json
"scripts": {
"cs-check": "phpcs",
"cs-fix": "phpcbf"
}
```
3. Create file `phpcs.xml` on base path of your repository with this content:
```xml
config
src
test
```
You can add or exclude some locations in that file.
For a reference please see: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-Ruleset
## Usage
* To run checks only:
```bash
$ composer cs-check
```
* To automatically fix many CS issues:
```bash
$ composer cs-fix
```
## Ignoring parts of a File
> Note: Before PHP_CodeSniffer version 3.2.0, `// @codingStandardsIgnoreStart` and `// @codingStandardsIgnoreEnd` were
> used. These are deprecated and will be removed in PHP_CodeSniffer version 4.0.
Disable parts of a file:
```php
$xmlPackage = new XMLPackage;
// phpcs:disable
$xmlPackage['error_code'] = get_default_error_code_value();
$xmlPackage->send();
// phpcs:enable
```
Disable a specific rule:
```php
// phpcs:disable Generic.Commenting.Todo.Found
$xmlPackage = new XMLPackage;
$xmlPackage['error_code'] = get_default_error_code_value();
// TODO: Add an error message here.
$xmlPackage->send();
// phpcs:enable
```
Ignore a specific violation:
```php
$xmlPackage = new XMLPackage;
$xmlPackage['error_code'] = get_default_error_code_value();
// phpcs:ignore Generic.Commenting.Todo.Found
// TODO: Add an error message here.
$xmlPackage->send();
```
## Development
> **New rules or Sniffs may not be introduced in minor or bugfix releases and should always be based on the develop
branch and queued for the next major release, unless considered a bugfix for existing rules.**
If you want to test changes against Laminas components or your own projects, install your forked
laminas-coding-standard globally with composer:
```bash
$ composer global config repositories.laminas-coding-standard vcs git@github.com:/laminas-coding-standard.git
$ composer global require --dev laminas/laminas-coding-standard:dev-
# For this to work, add this to your path: ~/.composer/vendor/bin
# Using `-s` prints the rules that triggered the errors so they can be reviewed easily. `-p` is for progress display.
$ phpcs -sp --standard=LaminasCodingStandard src test
```
Make sure you remove the global installation after testing from your global composer.json file!!!
Documentation can be previewed locally by installing [MkDocs](https://www.mkdocs.org/#installation) and run
`mkdocs serve`. This will start a server where you can read the docs.
## Reference
Rules can be added, excluded or tweaked locally, depending on your preferences. More information on how to do this can
be found here:
- [Coding Standard Tutorial](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Coding-Standard-Tutorial)
- [Configuration Options](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options)
- [Selectively Applying Rules](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-Ruleset#selectively-applying-rules)
- [Customisable Sniff Properties](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Customisable-Sniff-Properties)
PK _QNzV
.gitignorenu ٘ /.phpcs-cache
/clover.xml
/composer.lock
/coveralls-upload.json
/docs/html/
/laminas-mkdoc-theme.tgz
/laminas-mkdoc-theme/
/mkdocs.site.yml
/phpcs.log
/phpcs.xml
/phpunit.xml
/test/fix/
/vendor/
PK _QE
Y % src/LaminasCodingStandard/ruleset.xmlnu ٘
The Laminas coding standard.
PK _Qu0 0
mkdocs.ymlnu ٘ docs_dir: docs/book
site_dir: docs/html
extra:
project: Components
current_version: v2
versions:
- v2
- v1
installation:
composer_dev: true
nav:
- Home: index.md
- v2:
- 'Introduction': v2/intro.md
- 'Coding Style Guide': v2/coding-style-guide.md
- v1:
- 'Introduction': v1/intro.md
- 'Ruleset': v1/ruleset.md
site_name: laminas-coding-standard
site_description: 'The coding standard ruleset for Laminas components.'
repo_url: 'https://github.com/laminas/laminas-coding-standard'
PK _QĞAE E phpcs.xml.distnu ٘
The coding standard for LaminasCodingStandard itself.
src
PK _Q;bJ J .github/workflows/docs-build.ymlnu ٘ name: docs-build
on:
push:
branches:
- master
repository_dispatch:
types: docs-build
jobs:
build-deploy:
runs-on: ubuntu-latest
steps:
- name: Build Docs
uses: laminas/documentation-theme/github-actions/docs@master
env:
DOCS_DEPLOY_KEY: ${{ secrets.DOCS_DEPLOY_KEY }}
PK _QOx 1 .github/workflows/release-on-milestone-closed.ymlnu ٘ name: "Automatic Releases"
on:
milestone:
types:
- "closed"
jobs:
release:
name: "GIT tag, release & create merge-up PR"
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
- name: "Release"
uses: "laminas/automatic-releases@v1"
with:
command-name: "laminas:automatic-releases:release"
env:
"GITHUB_TOKEN": ${{ secrets.ORGANIZATION_ADMIN_TOKEN }}
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }}
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }}
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}
- name: "Create Merge-Up Pull Request"
uses: "laminas/automatic-releases@v1"
with:
command-name: "laminas:automatic-releases:create-merge-up-pull-request"
env:
"GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }}
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }}
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }}
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}
- name: "Create and/or Switch to new Release Branch"
uses: "laminas/automatic-releases@v1"
with:
command-name: "laminas:automatic-releases:switch-default-branch-to-next-minor"
env:
"GITHUB_TOKEN": ${{ secrets.ORGANIZATION_ADMIN_TOKEN }}
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }}
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }}
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}
- name: "Bump Changelog Version On Originating Release Branch"
uses: "laminas/automatic-releases@v1"
with:
command-name: "laminas:automatic-releases:bump-changelog"
env:
"GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }}
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }}
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }}
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}
- name: "Create new milestones"
uses: "laminas/automatic-releases@v1"
with:
command-name: "laminas:automatic-releases:create-milestones"
env:
"GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }}
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }}
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }}
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}
PK _Q@e e ) test/fixed/4.3.PropertiesAndConstants.phpnu ٘ */
private $bar;
/**
* @param IteratorAggregate $bar
*/
public function __construct(ArrayObject $bar)
{
$this->bar = $bar;
}
/**
* @param array $config
*/
public function doSomethingWithArray(array $config): void
{
$this->config = $config;
}
/**
* @param Generic $a
*/
public function genericWithoutItemsSpecification(Generic $a)
{
}
/**
* @param array[]&Traversable $a
*/
public function traversableIntersection(Traversable $a)
{
}
/**
* @param Traversable&array[] $a
*/
public function traversableIntersectionDifferentOrder(Traversable $a)
{
}
public function traversableNull(?Traversable $a)
{
}
/**
* @param array|array $a
*/
public function unionWithSameBase(array $a)
{
}
/**
* @param array|array|array $a
*/
public function unionWithSameBaseAndMoreTypes(array $a)
{
}
/**
* @param array|bool[] $a
*/
public function unionWithSameBaseToo(array $a)
{
}
/**
* @param array|array|array|null $a
*/
public function unionWithSameNullableBase(?array $a)
{
}
}
PK _QwI( test/fixed/2.2.Files.phpnu ٘ getMessage();
} catch (OtherThrowableType | AnotherThrowableType $e) {
echo $e->getMessage();
} finally {
echo 'Done!';
}
}
public function testUnreacableCatchBlock(): void
{
// All catch blocks MUST be reachable.
try {
$x = 1 + 2;
} catch (Throwable $e) {
echo $e;
} catch (InvalidArgumentException $e) {
echo $e; // unreachable!
}
}
}
PK _Q
\ " test/fixed/6.2.BinaryOperators.phpnu ٘ $b) {
$foo = $a + $b * $c;
}
}
}
PK _Q{ek k # test/fixed/6.3.TernaryOperators.phpnu ٘
*
*
*
* @internal
* @deprecated
*
* @link
* @uses
* @see
*
* @param
* @return
* @throws
*/
public function testDocBlockSpacing(): void
{
}
public function testInlineCommentMustBeAtTheEnd(): void
{
$hello = $world; /* comment */
$hello = $world; /* comment */
}
/**
* Sets a single-line title.
*
* The `param` and `return` tags should be omitted as they are already
* type hinted.
*/
public function setTitle(string $title): void
{
// there should be no docblock here
$this->title = $title;
}
/**
* All tags can be omitted as typehints describe it all.
*/
public function foo(bool $createNew): ?stdClass
{
if ($createNew) {
return new stdClass();
}
return null;
}
/**
* The returned array should be described with a `return` tag.
*
* @return SQLite3[] $connections
*/
public function testIdeAutoCompletion(): array
{
/** @var SQLite3 $sqlite */
foreach ($connections as $sqlite) {
// there should be no docblock here
$sqlite->open('/my/database/path');
}
return $connections;
}
}
PK _Q0_ " test/fixed/5.3.WhileAndDoWhile.phpnu ٘ testOperatorSpacing();
$this->testOperatorSpacing();
$this->testOperatorSpacing();
$this
->testOperatorSpacing();
$this->
testOperatorSpacing();
}
public function testUseStrictComparisonOperators(): void
{
// Loose comparison operators SHOULD NOT be used, use strict comparison
// operators instead.
// Fix that manually.
$foo == 123;
123 == $foo;
true != 0.0;
false <> true;
}
public function testUseNullCoalesceOperator(): void
{
// The null coalesce operator MUST be used when possible.
$a = $_GET['a'] ?? 'a';
$b = $bb ?? 'bb';
$c = $cc['c'] ?? 'c';
}
public function testAssignmentOperators(int $var): void
{
// Assignment operators SHOULD be used when possible.
$var &= 2;
$var |= 4;
$var .= '';
$var /= 10;
$var -= 100;
$var **= 2;
$var %= 2;
$var *= 1000;
$var += 4;
$var <<= 2;
$var >>= 2;
$var ^= 10;
$var += 10;
}
}
PK _Q&|u`J J # test/fixed/5.5.ForEachStructure.phpnu ٘ $value) {
echo sprintf('%d - %s', $key, $value);
}
}
}
PK _Qn test/fixed/2.6.Variables.phpnu ٘ > * test/fixed/3.DeclareNamespaceAndImport.phpnu ٘ sub(new DateInterval('P1D'))
->format(DATE_RFC3339)
);
new Baz();
}
public function testDeclareStatement(): void
{
// When wishing to declare strict types in files containing markup
// outside PHP opening and closing tags, the declaration MUST be on the
// first line of the file and include an opening PHP tag, the strict
// types declaration and closing tag.
//
// Declare statements MUST contain no spaces and MUST be exactly
// declare(strict_types=1) (with an optional semi-colon terminator).
//
// Block declare statements are allowed and MUST be formatted as below.
declare(ticks=1) {
// some code
}
}
}
PK _Q& p , test/fixed/4.ClassesPropertiesAndMethods.phpnu ٘ bar($arg1);
Foo::bar($arg2, $arg3);
}
public function testArguments(): void
{
// Argument lists MAY be split across multiple lines, where each
// subsequent line is indented once. When doing so, the first item in the
// list MUST be on the next line, and there MUST be only one argument per
// line. A single argument being split across multiple lines (as might be
// the case with an anonymous function or array) does not constitute
// splitting the argument list itself.
$foo->bar(
$longArgument,
$longerArgument,
$muchLongerArgument
);
$app->get('/hello/{name}', function ($name) use ($app) {
return 'Hello ' . $app->escape($name);
});
}
}
PK _Q= m m test/fixed/2.7.Arrays.phpnu ٘ 'value1',
'key2' => 'value2',
'keyTwenty' => 'value3',
];
$array2 = [
'one' => function (): void {
$foo = [1, 2, 3];
$barBar = [
1,
2,
3,
];
},
'longer' => 2,
3 => 'three',
];
}
public function testShortListSyntax(): void
{
// The short list syntax `[...]` SHOULD be used instead of `list(...)`.
[$a, $b, $c] = [1, 2, 3];
["a" => $a, "b" => $b, "c" => $c] = ["a" => 1, "b" => 2, "c" => 3];
[$a, $b] = [$b, $a];
}
}
PK _Q[Tl # test/fixed/2.5.KeywordsAndTypes.phpnu ٘ name;
}
public function testReturnedVariablesShouldBeUseful(): bool
{
// Returned variables SHOULD be useful and not be assign to a value and
// returned on the next line.
return true;
}
}
PK _Q@ә test/fixed/2.3.Lines.phpnu ٘ 0 && $n < 10)
|| ($n > 10 && $n < 20)
|| ($n > 20 && $n < 30)
) {
return $n;
}
if (
(
$expr1
&& $expr2
&& $expr3
&& $expr4
&& $expr5
&& $expr6
)
|| ($n > 100 && $n < 200)
|| ($n > 200 && $n < 300)
) {
return $n;
}
}
}
PK _QnI I &