Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.

Zend Coding Standard 2 #5

Closed
wants to merge 60 commits into from
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
dbacd12
Import strict ruleset
geerteltink Sep 5, 2018
5863c14
Allow functions inside functions
geerteltink Sep 5, 2018
06a5606
Allow @var for constants
geerteltink Sep 5, 2018
d27454d
Allow @since for noting API additions
geerteltink Sep 5, 2018
646eea1
Allow fancy yoda conditions as a defensive programming approach
geerteltink Sep 5, 2018
fa193f3
Forbid short open tag, but allow short echo tags for use in templates
geerteltink Sep 5, 2018
f1cef3f
Add documentation structure
geerteltink Sep 5, 2018
911065a
Use xmllint to validate against schema
geerteltink Sep 5, 2018
365acdf
Remove copyright in mkdocs config as it's not being used anymore
geerteltink Sep 5, 2018
b3146a6
Remove index.html because it's generated by the theme
geerteltink Sep 5, 2018
5c86655
Disable phpunit tests until there is something to test
geerteltink Sep 5, 2018
ce7ae4a
Use PSR-12 compatible imports
geerteltink Sep 6, 2018
3f602fa
Add rules to documentation
geerteltink Sep 6, 2018
39ba67a
Add some test cases
geerteltink Sep 6, 2018
e9d9a2d
Update docs for alias functions
geerteltink Sep 6, 2018
2d29543
Document the new way to ignore parts of a file phpcs:enable phpcs:dis…
geerteltink Sep 6, 2018
2397775
Don't allow fully qualified classes from global space
geerteltink Sep 6, 2018
a063051
Add useful tests
geerteltink Sep 6, 2018
29b05a0
Fix typo in ci script
geerteltink Sep 6, 2018
d35d34e
Don't remove xdebug as php nightly doesn't have it
geerteltink Sep 6, 2018
b4d915d
Test expected violations for fixable code
geerteltink Sep 6, 2018
45d14bd
Require ? when default value is null
geerteltink Sep 6, 2018
5b00974
Improve documentation formatting
geerteltink Sep 6, 2018
dc11e2e
Add PSR-12 test cases
geerteltink Sep 6, 2018
6dc1801
Update concatenation spacing test
geerteltink Sep 6, 2018
c7718be
Update expected phpcs report
geerteltink Sep 6, 2018
7367ecd
Improve concatenation tests
geerteltink Sep 7, 2018
a88527c
Add phpcs cache for speed improvement
geerteltink Sep 7, 2018
c15e28e
Document the coding standard and all rules
geerteltink Sep 7, 2018
d044763
First set of documentation improvements and fixes
geerteltink Sep 7, 2018
f722edd
More grammar fixes
geerteltink Sep 8, 2018
ba703a4
Reorder rules and disable double rules
geerteltink Sep 8, 2018
2702288
Add missing rule: Class name resolution via ::class
geerteltink Sep 8, 2018
b9509c8
Add coding-style-guide to mkdocs config
geerteltink Sep 8, 2018
4da5772
Add changelog for #5
geerteltink Sep 8, 2018
9737c95
Improve wording and add example for Generic.Classes.DuplicateClassName
geerteltink Sep 8, 2018
7ea79cc
It's raining outside, so more examples and improved formatting
geerteltink Sep 8, 2018
70b63af
Update phpcs config in readme
geerteltink Sep 8, 2018
f93740b
Update array indentation test
geerteltink Sep 9, 2018
c531490
Don't align equal statements, double arrow arrays or phpdoc comment tags
geerteltink Sep 11, 2018
aba1c3a
Remove early exit rule as it is overly aggressive when "fixing" the code
geerteltink Sep 11, 2018
a276b18
Add references
geerteltink Sep 11, 2018
bf0d951
Update changelog with latest changes
geerteltink Sep 11, 2018
3386b02
Update intro and readme
geerteltink Sep 11, 2018
300e613
Fix creation of double trailing commas on specific arrays
geerteltink Sep 11, 2018
61f3bc5
PSR-12: Force Unix LF (linefeed) line ending
geerteltink Sep 11, 2018
ea3de20
Allow global functions
geerteltink Sep 11, 2018
53a7dcd
Align comments, statements and arrays
geerteltink Sep 19, 2018
850f481
Align array double arrows
geerteltink Sep 19, 2018
5eaa798
Validate fixes before running tests
geerteltink Sep 19, 2018
41d35b9
Fix single arrow indention test
geerteltink Sep 19, 2018
3974380
Reset array alignment and start from scratch
geerteltink Sep 20, 2018
137dc8a
Update slevomat/coding-standard requirement and add regression test for
geerteltink Sep 20, 2018
61f6b4b
Add test for constant aligning
geerteltink Sep 20, 2018
5f2280d
Align double arrows in multiline arrays
geerteltink Sep 21, 2018
a3d45d7
Update expected errors report
geerteltink Sep 21, 2018
27b735f
Require php_codesniffer 3.3.2
geerteltink Oct 6, 2018
95213b5
Update array indentation tests
geerteltink Oct 6, 2018
38a2dea
Use new format to declare array properties
geerteltink Oct 6, 2018
7dc2f78
Update phpcs report
geerteltink Oct 6, 2018
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
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/clover.xml
/composer.lock
/coveralls-upload.json
/docs/html/
/phpcs.log
/phpcs.xml
/phpunit.xml
/vendor/
/zf-mkdoc-theme.tgz
/zf-mkdoc-theme/
36 changes: 36 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
dist: trusty
sudo: false
language: php

php:
- 7.1
- 7.2
- nightly

cache:
directories:
- $HOME/.composer/cache

before_install:
- phpenv config-rm xdebug.ini
- composer self-update

install: travis_retry composer update --prefer-dist

stages:
- Validate against schema

jobs:
allow_failures:
- php: nightly

include:
- stage: Validate against schema
addons:
apt:
packages:
- libxml2-utils
script: xmllint --noout --schema vendor/squizlabs/php_codesniffer/phpcs.xsd src/ZendCodingStandard/ruleset.xml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! 👍


notifications:
email: false
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2016, Zend Technologies USA, Inc.
Copyright (c) 2016-2018, Zend Technologies USA, Inc.

All rights reserved.

Expand Down
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
Zend Framework Coding Standard
==============================
# zend-coding-standard

Repository with all coding standard ruleset for Zend Framework repositories.
[![Build Status](https://secure.travis-ci.org/zendframework/zend-coding-standard.svg?branch=master)](https://secure.travis-ci.org/zendframework/zend-coding-standard)

The coding standard ruleset for Zend Framework components.

Installation
------------
## Installation

1. Install the module via composer by running:

Expand All @@ -27,7 +26,7 @@ Installation
```xml
<?xml version="1.0"?>
<ruleset name="Zend Framework Coding Standard">
<rule ref="./vendor/zendframework/zend-coding-standard/ruleset.xml"/>
<rule ref="ZendCodingStandard"/>

<!-- Paths to check -->
<file>config</file>
Expand All @@ -39,9 +38,7 @@ Installation
You can add or exclude some locations in that file.
For a reference please see: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml


Usage
-----
## Usage

* To run checks only:

Expand All @@ -50,7 +47,7 @@ Usage
```

* To automatically fix many CS issues:

```bash
$ composer cs-fix
```
27 changes: 25 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
{
"name": "zendframework/zend-coding-standard",
"description": "Zend Framework coding standard",
"type": "phpcodesniffer-standard",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm so happy that composer has made things like plugin registration automated via package type!

"description": "Zend Framework Coding Standard",
"license": "BSD-3-Clause",
"keywords": [
"zf",
"zendframework",
"coding standard"
],
"support": {
"docs": "https://docs.zendframework.com/zend-coding-standard/",
"issues": "https://github.com/zendframework/zend-coding-standard/issues",
"source": "https://github.com/zendframework/zend-coding-standard",
"rss": "https://github.com/zendframework/zend-coding-standard/releases.atom",
"chat": "https://zendframework-slack.herokuapp.com",
"forum": "https://discourse.zendframework.com/c/questions/components"
},
"require": {
"squizlabs/php_codesniffer": "^2.7"
"php": "^7.1",
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.4",
"slevomat/coding-standard": "^4.7.3",
"squizlabs/php_codesniffer": "^3.3.1"
},
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"autoload": {
"psr-4": {
"ZendCodingStandard\\Sniffs\\": "src/ZendCodingStandard/Sniffs"
}
}
}
2 changes: 1 addition & 1 deletion CONDUCT.md → docs/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contributor Code of Conduct

The Zend Framework project adheres to [The Code Manifesto](http://codemanifesto.com)
This project adheres to [The Code Manifesto](http://codemanifesto.com)
as its guidelines for contributor interactions.

## The Code Manifesto
Expand Down
189 changes: 189 additions & 0 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
# CONTRIBUTING

## RESOURCES

If you wish to contribute to this project, please be sure to
read/subscribe to the following resources:

- [Coding Standards](https://github.com/zendframework/zend-coding-standard)
- [Forums](https://discourse.zendframework.com/c/contributors)
- [Chat](https://zendframework-slack.herokuapp.com)
- [Code of Conduct](CODE_OF_CONDUCT.md)

If you are working on new features or refactoring
[create a proposal](https://github.com/zendframework/zend-coding-standard/issues/new).

## RUNNING TESTS

To run tests:

- Clone the repository:

```console
$ git clone git://github.com/zendframework/zend-coding-standard.git
$ cd zend-coding-standard
```

- Install dependencies via composer:

```console
$ composer install
```

If you don't have `composer` installed, please download it from https://getcomposer.org/download/

- Run the tests using the "test" command shipped in the `composer.json`:

```console
$ composer test
```

You can turn on conditional tests with the `phpunit.xml` file.
To do so:

- Copy `phpunit.xml.dist` file to `phpunit.xml`
- Edit `phpunit.xml` to enable any specific functionality you
want to test, as well as to provide test values to utilize.

## Running Coding Standards Checks

First, ensure you've installed dependencies via composer, per the previous
section on running tests.

To run CS checks only:

```console
$ composer cs-check
```

To attempt to automatically fix common CS issues:

```console
$ composer cs-fix
```

If the above fixes any CS issues, please re-run the tests to ensure
they pass, and make sure you add and commit the changes after verification.

## Recommended Workflow for Contributions

Your first step is to establish a public repository from which we can
pull your work into the master repository. We recommend using
[GitHub](https://github.com), as that is where the component is already hosted.

1. Setup a [GitHub account](https://github.com/), if you haven't yet
2. Fork the repository (https://github.com/zendframework/zend-coding-standard)
3. Clone the canonical repository locally and enter it.

```console
$ git clone git://github.com/zendframework/zend-coding-standard.git
$ cd zend-coding-standard
```

4. Add a remote to your fork; substitute your GitHub username in the command
below.

```console
$ git remote add {username} git@github.com:{username}/zend-coding-standard.git
$ git fetch {username}
```

### Keeping Up-to-Date

Periodically, you should update your fork or personal repository to
match the canonical ZF repository. Assuming you have setup your local repository
per the instructions above, you can do the following:


```console
$ git checkout master
$ git fetch origin
$ git rebase origin/master
# OPTIONALLY, to keep your remote up-to-date -
$ git push {username} master:master
```

If you're tracking other branches -- for example, the "develop" branch, where
new feature development occurs -- you'll want to do the same operations for that
branch; simply substitute "develop" for "master".

### Working on a patch

We recommend you do each new feature or bugfix in a new branch. This simplifies
the task of code review as well as the task of merging your changes into the
canonical repository.

A typical workflow will then consist of the following:

1. Create a new local branch based off either your master or develop branch.
2. Switch to your new local branch. (This step can be combined with the
previous step with the use of `git checkout -b`.)
3. Do some work, commit, repeat as necessary.
4. Push the local branch to your remote repository.
5. Send a pull request.

The mechanics of this process are actually quite trivial. Below, we will
create a branch for fixing an issue in the tracker.

```console
$ git checkout -b hotfix/9295
Switched to a new branch 'hotfix/9295'
```

... do some work ...


```console
$ git commit
```

... write your log message ...


```console
$ git push {username} hotfix/9295:hotfix/9295
Counting objects: 38, done.
Delta compression using up to 2 threads.
Compression objects: 100% (18/18), done.
Writing objects: 100% (20/20), 8.19KiB, done.
Total 20 (delta 12), reused 0 (delta 0)
To ssh://git@github.com/{username}/zend-coding-standard.git
b5583aa..4f51698 HEAD -> master
```

To send a pull request, you have two options.

If using GitHub, you can do the pull request from there. Navigate to
your repository, select the branch you just created, and then select the
"Pull Request" button in the upper right. Select the user/organization
"zendframework" (or whatever the upstream organization is) as the recipient.

#### What branch to issue the pull request against?

Which branch should you issue a pull request against?

- For fixes against the stable release, issue the pull request against the
"master" branch.
- For new features, or fixes that introduce new elements to the public API (such
as new public methods or properties), issue the pull request against the
"develop" branch.

### Branch Cleanup

As you might imagine, if you are a frequent contributor, you'll start to
get a ton of branches both locally and on your remote.

Once you know that your changes have been accepted to the master
repository, we suggest doing some cleanup of these branches.

- Local branch cleanup

```console
$ git branch -d <branchname>
```

- Remote branch removal

```console
$ git push {username} :<branchname>
```
19 changes: 19 additions & 0 deletions docs/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- [ ] I was not able to find an [open](https://github.com/zendframework/zend-coding-standard/issues?q=is%3Aopen) or [closed](https://github.com/zendframework/zend-coding-standard/issues?q=is%3Aclosed) issue matching what I'm seeing.
- [ ] This is not a question. (Questions should be asked on [chat](https://zendframework.slack.com/) ([Signup here](https://zendframework-slack.herokuapp.com/)) or our [forums](https://discourse.zendframework.com/).)

Provide a narrative description of what you are trying to accomplish.

### Code to reproduce the issue

<!-- Please provide the minimum code necessary to recreate the issue -->

```php
```

### Expected results

<!-- What do you think should have happened? -->

### Actual results

<!-- What did you actually observe? -->
25 changes: 25 additions & 0 deletions docs/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Provide a narrative description of what you are trying to accomplish:

- [ ] Are you fixing a bug?
- [ ] Detail how the bug is invoked currently.
- [ ] Detail the original, incorrect behavior.
- [ ] Detail the new, expected behavior.
- [ ] Base your feature on the `master` branch, and submit against that branch.
- [ ] Add a regression test that demonstrates the bug, and proves the fix.
- [ ] Add a `CHANGELOG.md` entry for the fix.

- [ ] Are you creating a new feature?
- [ ] Why is the new feature needed? What purpose does it serve?
- [ ] How will users use the new feature?
- [ ] Base your feature on the `develop` branch, and submit against that branch.
- [ ] Add only one feature per pull request; split multiple features over multiple pull requests
- [ ] Add tests for the new feature.
- [ ] Add documentation for the new feature.
- [ ] Add a `CHANGELOG.md` entry for the new feature.

- [ ] Is this related to quality assurance?
<!-- Detail why the changes are necessary -->

- [ ] Is this related to documentation?
<!-- Is it a typographical and/or grammatical fix? -->
<!-- Is it new documentation? -->
Loading