Commit 15c43d25 authored by Benoit Mortier's avatar Benoit Mortier

🎉 feat: First import of development tools

Signed-off-by: Benoit Mortier's avatarBenoit Mortier <benoit.mortier@opensides.be>
parent 8640c3f8
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at <coc@fusiondirectory.org>. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [https://www.contributor-covenant.org/version/1/4][version]
[homepage]: https://www.contributor-covenant.org
[version]: https://www.contributor-covenant.org/version/1/4/
# Contributing to FusionDirectory projects
:tada: First off, thanks for taking the time to contribute!
> «Here's a list of our guidelines, If you want to share a best practice, or think one of these guidelines should be removed, feel free to share it with us.»
## Table Of Contents
1. [TL;DR](#tldr)
2. [Code of Conduct](#code-of-conduct)
3. [I just have a question!](#i-just-have-a-question)
4. [How Can I Contribute?](#how-can-i-contribute)
* [Finding Wonderful Bugs](#finding-wonderful-bugs)
* [Any Feedback To Enhance Our Apps](#any-feedback-to-enhance-our-apps)
* [Your Awesome And Mighty Codes Contributions](#your-awesome-and-mighty-codes-contributions)
5. [Coding with style](#coding-with-style)
* [Git Commit Messages](#git-commit-messages)
* [PHP Style Guide](#php-style-guide
6. [Licensing](#licensing)
---
## TL;DR
You're so excited to contribute that you do not have time to read the entire document. Here you will find some keys to quickly and safety contribute. :wink:
1. [Our communication Channels](https://www.fusiondirectory.org/contact-us/). Feel free to discuss with us.
2. Just be cool and respectful with others
3. create an FusionDirectory project account at [FusionDirectory Sign UP](https://register.fusiondirectory.org)
4. Use our `PHP CodeSniffer <http://pear.php.net/package/PHP_CodeSniffer>`_ rules to check code compliance [CodeSniffer](https://fusiondirectory-developer-documentation.readthedocs.io/en/latest/codingstandards.html#checking-standards)
5. Your code should be tested
6. Respect this simple commit message template
```
<emoji> <type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>
```
The **header** is mandatory and the **scope** of the header is optional.
Where type can be :
* **feat**: A new feature
* **fix**: A bug fix
* **core**: Code for the Core
* **docs**: Documenting the code or writing new documentation
* **style**: Cosmetics purpose
* **test**: Adding missing or correcting tests
7. For the subject, use the present tense ("Add feature" not "Added feature")
8. Should be submitted through [FusionDirectory gitlab](https://gitlab.fusiondirectory.org) via a pull request on the 1.x-dev branch.
Now, if you want to go further, sit comfortably at the fireplace, grab your glasses and immerse yourself in our documentation.
## Code Of Conduct
All projects and everyone participating in it is governed by [FusionDirectory Code Of Conduct](./CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. Please read this before.
## I just have a question!
> **Note:** Please don't file an issue to ask a question. You'll get faster results by using the resource below.
We have an various channel of communications
* [#fusiondirectory, the irc channel of FusionDirectory on freenode](https://webchat.freenode.net/), channel #fusiondirectory
* [FusionDirectory Users mailing list](https://lists.fusiondirectory.org/wws/info/users)
* [FusionDirectory dev mailing list](https://lists.fusiondirectory.org/wws/info/developpers)
## How Can I Contribute?
So, you've developed a new cool feature? Fixed an annoying bug? Found a mistake? We'd be happy to hear from you! :+1:
### Register for a FusionDirectory project account
To create a FusionDirectory project Account you must go to
* [FusionDirectory Sign UP](https://register.fusiondirectory.org)
### Put FusionDirectory in debug mode
* Go into FusionDirectory configuration
* Activate the displaying of PHP errors, and the TRACE debug level
### Finding Wonderful Bugs
>This section guides you through submitting a bug report. Following these guidelines helps maintainers and the community understand your report, reproduce the behavior, and find related reports.
When you are creating a bug report, please include as many details as possible. Fill out the required template, the information it asks for helps us resolve issues faster. We have a [template](Bugs.md) to create issues. Please use this template.
Explain the problem and include additional details to help maintainers reproduce the problem:
* **Use a clear and descriptive title** for the issue to identify the problem.
* **Describe the exact steps which reproduce the problem** in as many details as possible. For example, start by explaining wich brower and it's version. When listing steps, don't just say what you did, but explain how you did it. For example, if you moved the cursor to the end of an input, explain if you used the mouse, or a keyboard.
* **Describe the behavior** you observed after following the steps and point out what exactly is the problem with that behavior.
* **Explain which behavior** you expected to see instead and why.
* **Include screenshots and animated GIFs** which show you following the described steps and clearly demonstrate the problem. You can use [this tool](http://www.cockos.com/licecap/) to record GIFs on macOS and Windows, and this tool or [this tool](https://github.com/GNOME/byzanz) on Linux.
* **Include the PHP errors and trace** collected at the debug step above
* **If the problem is linked to a specific LDAP entry** attach its LDAP dump.
### Any Feedback To Enhance FusionDirectory
>This section guides you through submitting an enhancement suggestion, including completely new features and minor improvements to existing functionality. Following these guidelines helps maintainers and the community understand your suggestion and find related suggestions.
Fill in [the template](Bugs.md), including the steps that you imagine you would take if the feature you're requesting existed.
Enhancement suggestions are tracked on [FusionDirectory](https://gitlab.fusiondirectory.org/fusiondirectory/fd/issues) for the core program, and
[FusionDirectory Plugins](https://gitlab.fusiondirectory.org/fusiondirectory/fd-plugins/issues) for plugins.
After you've determined which repository your enhancement suggestion is related to, create an issue on that repository and provide the following information:
* **Use a clear and descriptive title** for the issue to identify the suggestion.
* **Provide a step-by-step description of the suggested enhancement** in as many details as possible.
* **Describe the current behavior** and **explain which behavior you expected to see instead** and why.
* **Include screenshots and animated GIFs** which help you demonstrate the steps which the suggestion is related to. You can use [this tool](http://www.cockos.com/licecap/) to record GIFs on macOS and Windows, and [this tool](https://github.com/colinkeenan/silentcast) or [this tool](https://github.com/GNOME/byzanz) on Linux.
* **Explain why this enhancement would be useful** to most FusionDirectory users.
### Your awesome And Mighty Codes Contributions
>This section guides you through submitting an enhancement suggestion, including completely new features and minor improvements to existing functionality. Following these guidelines helps maintainers and the community understand your suggestion and find related suggestions.
* Fill in [the required template](Merge.md)
* Include screenshots and animated GIFs in your pull request whenever possible.
* Follow the [Coding standards](https://fusiondirectory-developer-documentation.readthedocs.io/en/latest/codingstandards.html#coding-standards)
* Use our `PHP CodeSniffer <http://pear.php.net/package/PHP_CodeSniffer>`_ rules to check code compliance [CodeSniffer](https://fusiondirectory-developer-documentation.readthedocs.io/en/latest/codingstandards.html#checking-standards)
* End all files with a newline
## Coding with style
### Git Commit Messages
>Having a good guideline for creating commits and sticking to it makes working with Git and collaborating with others a lot easier.
Here are some rules of thumb :
* Use the present tense ("Add feature" not "Added feature")
* If you have a body, separate the subject from the body with a newline
* Limit the subject line to 72 characters
* Do not end the subject line with a period
* Use imperative [mood](https://en.wikipedia.org/wiki/Imperative_mood#English) in the subject line
* If the subject is not clear enough, use the body to explain what and why as opposed to how
* Consider starting the commit message with an applicable emoji, when you feel it's an important commit :
* :tada: When first / initial commit
* :sparkles: When introducing new features
* :ambulance: When fixing a bug
* :handshake: When merging files
* :tractor: When you changing file structure or refactoring
* :books: When writing docs
* :gem: When new Release
* :lipstick: For cosmetics purposes
#### Commit Message Format
Each commit message consists of a **header**, a **body** and a **footer**. The header has a special format that includes a **type**, a **scope** and a **subject**:
```
<emoji> <type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>
```
The **header** is mandatory and the **scope** of the header is optional.
Examples:
```
:sparkles: feat(supann): Make supannRefId multivaluated
supannRefId on Structure object is too small and mono valued
close #5685
```
### PHP style Guide
To be sure to respect our guidelines, read [Coding standards](https://fusiondirectory-developer-documentation.readthedocs.io/en/latest/codingstandards.html#coding-standards)
## Licensing
For all new projects and most of older one we use **GPL2+ License**. You can find it [here](../LICENSE.md).
Make sure to use resources that we have the rights to use. Copyrighted images and videos may cause legal problems.
---
This document is strongly inspired by the following resources: [ovh-ux-guidelines
](https://github.com/ovh-ux/ovh-ux-guidelines), [project-guidelines](https://github.com/wearehive/project-guidelines), [Atom Guidelines](https://github.com/atom/atom/blob/master/CONTRIBUTING.md#reporting-bugs), [Angularjs guidelines](https://github.com/angular/angular.js/blob/master/CONTRIBUTING.md).
With love :heart:
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="filterdef">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="definition" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="search" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="element" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:simpleType name="regexA">
<xsd:restriction base="xsd:string">
<xsd:pattern value="true|false"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="regexB">
<xsd:restriction base="xsd:string">
<xsd:pattern value="([a-zA-Z0-9/.-])+"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="regexC">
<xsd:restriction base="xsd:string">
<xsd:pattern value="([a-zA-Z0-9])+"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="regexD">
<xsd:restriction base="xsd:string">
<xsd:pattern value="([A-Z])+"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="definition">
<xsd:complexType mixed="true">
<xsd:all>
<xsd:element ref="category" minOccurs="1"/>
<xsd:element ref="template" minOccurs="1"/>
<xsd:element ref="initial" minOccurs="0"/>
</xsd:all>
</xsd:complexType>
</xsd:element>
<xsd:element name="category" type="regexB"/>
<xsd:element name="template" type="regexB"/>
<xsd:element name="initial" type="regexA"/>
<xsd:element name="search">
<xsd:complexType mixed="true">
<xsd:sequence>
<xsd:element ref="query" maxOccurs="unbounded"/>
<xsd:element ref="scope"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="query">
<xsd:complexType mixed="true">
<xsd:sequence>
<xsd:element ref="backend"/>
<xsd:element ref="filter"/>
<xsd:element ref="attribute" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="backend" type="regexD"/>
<xsd:element name="filter" type="xsd:string"/>
<xsd:element name="attribute" type="regexC"/>
<xsd:element name="scope">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="auto|sub|one"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="element">
<xsd:complexType mixed="true">
<xsd:sequence>
<xsd:element ref="type"/>
<xsd:element ref="tag"/>
<xsd:element ref="alphabet" minOccurs="0"/>
<xsd:element ref="default" minOccurs="0"/>
<xsd:element ref="unset"/>
<xsd:element ref="set"/>
<xsd:element ref="value" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="autocomplete" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="type">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="textfield"/>
<xsd:enumeration value="combobox"/>
<xsd:enumeration value="checkbox"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="tag" type="regexD"/>
<xsd:element name="alphabet" type="regexA"/>
<xsd:element name="default" type="xsd:string"/>
<xsd:element name="unset" type="xsd:string"/>
<xsd:element name="set" type="xsd:string"/>
<xsd:element name="autocomplete">
<xsd:complexType mixed="true">
<xsd:sequence>
<xsd:element ref="backend"/>
<xsd:element ref="filter"/>
<xsd:element ref="attribute"/>
<xsd:element ref="frequency" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="characters" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="base" minOccurs="0"/>
<xsd:element ref="scope" minOccurs="0"/>
<xsd:element ref="category" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="objectbase" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="key" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="frequency" type="xsd:float"/>
<xsd:element name="characters" type="xsd:int"/>
<xsd:element name="base" type="xsd:string"/>
<xsd:element name="objectbase" type="xsd:string"/>
<xsd:element name="value">
<xsd:complexType mixed="true">
<xsd:all>
<xsd:element ref="key" minOccurs="1"/>
<xsd:element ref="label" minOccurs="1"/>
</xsd:all>
</xsd:complexType>
</xsd:element>
<xsd:element name="key" type="xsd:string"/>
<xsd:element name="label" type="xsd:string"/>
</xsd:schema>
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!-- general declarations multiple times used in this document-->
<xsd:element name="label" type="regexB"/>
<xsd:simpleType name="regexB">
<xsd:restriction base="xsd:string">
<xsd:pattern value="([a-zA-Z0-9/. _-])+"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="regexC">
<xsd:restriction base="xsd:string">
<xsd:pattern value="([a-zA-Z0-9])+"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="regexE">
<xsd:restriction base="xsd:string">
<xsd:pattern value="(!)?([a-zA-Z0-9])+"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="regexF">
<xsd:restriction base="xsd:string">
<xsd:pattern value="([0-9|px%;rlc])+"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="regexType">
<xsd:restriction base="xsd:string">
<xsd:pattern value="sub|entry|snapshot|copypaste|separator|exporter|daemon"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="regexAcl">
<xsd:restriction base="xsd:string">
<xsd:pattern value="(([a-zA-Z0-9])+)?(/([a-zA-Z0-9])+)?(\[([cdrwm])+\])?"/>
</xsd:restriction>
</xsd:simpleType>
<!-- first element of xml tree -->
<xsd:element name="list">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="definition"/>
<xsd:element ref="table"/>
<xsd:element ref="actionmenu" minOccurs="0"/>
<xsd:element ref="actiontriggers" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="definition">
<xsd:complexType mixed="true">
<xsd:sequence>
<xsd:element name="departmentBrowser" type="xsd:boolean" minOccurs="0" default="true"/>
<xsd:element name="departmentRootVisible" type="xsd:boolean" minOccurs="0" default="true"/>
<xsd:element name="baseMode" type="xsd:boolean" minOccurs="0"/>
<xsd:element name="multiSelect" type="xsd:boolean" minOccurs="0"/>
<xsd:element name="template" type="regexB"/>
<xsd:element name="module" type="regexC"/>
<xsd:element ref="label"/>
<xsd:element name="defaultSortColumn" type="xsd:integer" minOccurs="0" maxOccurs="1" default="1"/>
<xsd:element ref="objectType" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="objectType">
<xsd:complexType mixed="true">
<xsd:sequence>
<xsd:element ref="label"/>
<xsd:element name="objectClass" type="regexE" maxOccurs="unbounded"/>
<xsd:element name="category" type="regexB"/>
<xsd:element name="class" type="regexC"/>
<xsd:element name="image" type="regexB"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="table">
<xsd:complexType mixed="true">
<xsd:sequence>
<xsd:element name="layout" type="regexF"/>
<xsd:element ref="department" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="column" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="department">
<xsd:complexType mixed="true">
<xsd:sequence>
<xsd:element name="value" type="xsd:string"/>
<xsd:element name="span" type="xsd:integer" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="column">
<xsd:complexType mixed="true">
<xsd:sequence>
<xsd:element ref="label"/>
<xsd:element name="value" type="xsd:string"/>
<xsd:element name="sortAttribute" type="regexC" minOccurs="0"/>
<xsd:element name="sortType" type="regexSortType" minOccurs="0"/>
<xsd:element name="export" type="xsd:boolean" minOccurs="0" default="true"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:simpleType name="regexSortType">
<xsd:restriction base="xsd:string">
<xsd:pattern value="int|string|date"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="export" type="xsd:string"/><!--
actionmenu -->
<xsd:element name="actionmenu">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded" minOccurs="0">
<xsd:element ref="action"/>
</xsd:choice>
</xsd:complexType>
</xsd:element>
<xsd:element name="action">
<xsd:complexType mixed="true">
<xsd:choice maxOccurs="unbounded" minOccurs="0">
<xsd:element name="type" type="regexType"/>
<xsd:element name="label" type="xsd:string"/>
<xsd:element name="image" minOccurs="0"/>
<xsd:element name="name" type="xsd:string" minOccurs="0"/>
<xsd:element name="acl" type="regexAcl" minOccurs="0"/>
<xsd:element ref="objectclass" minOccurs="0"/>
<xsd:element ref="action"/>
</xsd:choice>
</xsd:complexType>
</xsd:element>
<xsd:element name="objectclass" type="xsd:string"/><!--
actiontriggers -->
<xsd:element name="actiontriggers">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded" minOccurs="0">
<xsd:element ref="action"/>
</xsd:choice>
<xsd:attribute name="snapshot" type="xsd:boolean" use="required"/>
<xsd:attribute name="copypaste" type="xsd:boolean" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<?php
/**
* FDStandard_Sniffs_Foreach_ReferenceSniff.
*
* Checks that foreach using references are followed by an unset
*
* @author Côme Bernigaud <come.bernigaud@laposte.net>
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
*/
class FDStandard_Sniffs_Foreach_ReferenceSniff implements PHP_CodeSniffer_Sniff
{
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_FOREACH);
}//end register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
/* Find the as token of the foreach */
$as = $phpcsFile->findNext(T_AS, $tokens[$stackPtr]['parenthesis_opener']+1, $tokens[$stackPtr]['parenthesis_closer']);
if (!$as) {
return;
}
/* Search for a reference between as and closing parenthesis */
$ref = $phpcsFile->findNext(T_BITWISE_AND, $as+1, $tokens[$stackPtr]['parenthesis_closer']);
if (!$ref) {
return;
}
$error = 'Foreach token using a reference should unset it afterwards';
if ($next = $phpcsFile->findNext(T_WHITESPACE, $tokens[$stackPtr]['scope_closer']+1, NULL, TRUE)) {
if ($tokens[$next]['content'] == 'unset') {
return;
}
$error .= ' (Expected unset, found '.$tokens[$next]['content'].')';
}
$phpcsFile->addError($error, $stackPtr, 'UnsetReference');
}//end process()
}//end class
?>
<?php
/**
* FDStandard_Sniffs_Returns_ParenthesisSniff.
*
* Checks that returns does not use parenthesis (expect for logical algebra)
*
* @author Côme Bernigaud <come.bernigaud@laposte.net>
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
*/
class FDStandard_Sniffs_Returns_ParenthesisSniff implements PHP_CodeSniffer_Sniff
{
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_RETURN);
}//end register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
//Check that there is a space after the return token (or a semicolon)
if (($tokens[$stackPtr+1]['code'] !== T_WHITESPACE) && ($tokens[$stackPtr+1]['code'] !== T_SEMICOLON)) {
$error = 'Token "'.$tokens[$stackPtr]['content'].'" should be followed by a space';
$phpcsFile->addError($error, $stackPtr, 'ReturnAfterSpace');
}
$nonWhiteSpace = $stackPtr+1;
while (in_array($tokens[$nonWhiteSpace]['code'], PHP_CodeSniffer_Tokens::$emptyTokens))
{
$nonWhiteSpace++;
}
if ($tokens[$nonWhiteSpace]['code'] === T_OPEN_PARENTHESIS) {
/* Check that this parenthesis block englobe the whole return content */
$openingParenthesis = $tokens[$nonWhiteSpace]['parenthesis_opener'];
$closingParenthesis = $tokens[$nonWhiteSpace]['parenthesis_closer'];
$nonWhiteSpace = $closingParenthesis+1;
while (in_array($tokens[$nonWhiteSpace]['code'], PHP_CodeSniffer_Tokens::$emptyTokens))
{
$nonWhiteSpace++;
}
$semiColon = $phpcsFile->findNext(T_SEMICOLON,$stackPtr+1);
if ($semiColon == $nonWhiteSpace) {
/* Check that this is not logical algebra */
$tobecheckedToken = $openingParenthesis;
$parenthesisAuthorized = array_merge(PHP_CodeSniffer_Tokens::$comparisonTokens,PHP_CodeSniffer_Tokens::$booleanOperators);
$parenthesisAuthorized[] = T_INLINE_THEN;
$ok = FALSE;
while ($tobecheckedToken = $phpcsFile->findNext($parenthesisAuthorized, $tobecheckedToken+1, $closingParenthesis)) {
if (end($tokens[$tobecheckedToken]['nested_parenthesis']) == $closingParenthesis) {
$ok = TRUE;
break;
}
}
if (!$ok) {
/* Complain */
$error = 'Token "'.$tokens[$stackPtr]['content'].'" should not use parenthesis';
$phpcsFile->addError($error, $stackPtr, 'ReturnParenthesis');
}
}
}
}//end process()
}//end class
?>
<?php
/**
* FDStandard_Sniffs_WhiteSpace_AssignmentSpacingSniff.
*
* Checks that assignment blocks have aligned equals signs
*
* Modified version of PHP_CodeSniffer Generic_Sniffs_Function_FunctionCallArgumentSpacingSniff
* by Greg Sherwood <gsherwood@squiz.net> and Marc McIntyre <mmcintyre@squiz.net>
*
* @author Côme Bernigaud <come.bernigaud@laposte.net>
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
*/
class FDStandard_Sniffs_WhiteSpace_AssignmentSpacingSniff implements PHP_CodeSniffer_Sniff
{
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return PHP_CodeSniffer_Tokens::$assignmentTokens;
}//end register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
//~ $blockClosers = array(T_CLOSE_CURLY_BRACKET, T_CLOSE_SQUARE_BRACKET, T_CLOSE_PARENTHESIS);
if ($prevAssignment = $phpcsFile->findPrevious(array(T_OPEN_PARENTHESIS),$stackPtr-1)) {
if ($tokens[$prevAssignment]['line'] == $tokens[$stackPtr]['line']) {
return; // It's not an assignment block
}
}
if ($prevAssignment = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$assignmentTokens,$stackPtr-1)) {
if ($tokens[$prevAssignment]['line'] == $tokens[$stackPtr]['line']-1) {
return; // We're not the first assignment of the block
}
if ($tokens[$prevAssignment]['line'] == $tokens[$stackPtr]['line']) {
return; // It's not an assignment block