PHP_CodeSniffer rules and sniffs to enforce Uncanny Owl coding conventions.
- PHP 7.4 or higher
- Composer
composer global require uocs/uncanny-owl-coding-standardscomposer require --dev uocs/uncanny-owl-coding-standardsAfter installation, you can use the standards in several ways:
# Check coding standards
composer uocs [path]
# Fix coding standards
composer uocbf [path]
# Use strict mode
composer uocs-strict [path]
composer uocbf-strict [path]# Check coding standards
vendor/bin/phpcs --standard=Uncanny-Owl [path]
# Fix coding standards
vendor/bin/phpcbf --standard=Uncanny-Owl [path]The UOCS includes and extends the following standards:
- WordPress Coding Standards
- PHP Compatibility
- PHPCSExtra
- Custom Uncanny Owl rules
Uncanny-Owl: Default standard with common rulesUncanny-Owl-Strict: Stricter version with additional checks
You can override the default ruleset for your project in two ways:
- Project-specific ruleset (Recommended):
Create a
phpcs.xmlorphpcs.xml.distin your project root:
<?xml version="1.0"?>
<ruleset name="Custom Project Standard">
<!-- Use Uncanny-Owl as base -->
<rule ref="Uncanny-Owl">
<!-- Exclude rules you don't want -->
<exclude name="WordPress.Files.FileName"/>
</rule>
<!-- Add your own custom rules -->
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<!-- Configure specific rules -->
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="120"/>
</properties>
</rule>
<!-- Define your paths -->
<file>src/</file>
<file>tests/</file>
<!-- Define exclusions -->
<exclude-pattern>/vendor/*</exclude-pattern>
<exclude-pattern>/node_modules/*</exclude-pattern>
</ruleset>- Command-line Override:
# Using composer script
composer uocs --standard=/path/to/your/custom-ruleset.xml [path]
# Or directly with PHPCS
vendor/bin/phpcs --standard=/path/to/your/custom-ruleset.xml [path]- Install the PHP Sniffer & Beautifier extension
- Configure settings.json:
{
"phpSniffer.standard": "Uncanny-Owl",
"phpSniffer.run": "onType"
}- Go to Settings → PHP → Quality Tools → PHP_CodeSniffer
- Set PHP_CodeSniffer path to your vendor/bin/phpcs
- Go to Settings → Editor → Inspections
- Enable PHP → Quality Tools → PHP_CodeSniffer validation
- Set 'Coding Standard' to Uncanny-Owl
- pipeline: "Code Standards"
trigger_mode: "ON_EVERY_PUSH"
ref_name: "refs/heads/*"
actions:
- action: "Install Dependencies"
type: "BUILD"
working_directory: "/buddy/app"
docker_image_name: "library/php"
docker_image_tag: "8.1"
execute_commands:
- composer install
- action: "Check Coding Standards"
type: "BUILD"
working_directory: "/buddy/app"
docker_image_name: "library/php"
docker_image_tag: "8.1"
execute_commands:
- composer uocsname: PHP_CodeSniffer
on: [push, pull_request]
jobs:
phpcs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
- name: Install Dependencies
run: composer install
- name: Run PHPCS
run: composer uocs-
Standards Not Found
- Ensure Composer installation was successful
- Try running
composer installagain - Check if the standard is listed in
vendor/bin/phpcs -i
-
Path Issues
- Use relative paths from your project root
- Ensure the path exists and is readable
For detailed output, add -v to the composer command:
composer uocs -v [path]- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For support, please open an issue in the GitHub repository or contact the Uncanny Owl development team.
- Install the PHP Sniffer & Beautifier extension
- Configure settings.json:
{
"phpsab.standard": "Uncanny-Owl",
"phpsab.executablePathCS": "/usr/local/bin/uocs",
"phpsab.executablePathCBF": "/usr/local/bin/uocbf"
}- Go to Settings → PHP → Quality Tools → PHP_CodeSniffer
- Set PHP_CodeSniffer path to the
uocsbinary - In Editor → Inspections → PHP → Quality Tools
- Enable PHP_CodeSniffer and select "Uncanny-Owl" standard
- Standards Not Found
make reinstall- Permission Issues
sudo chmod +x ./bin/uocs ./bin/uocbf- Path Issues
./bin/uocs --debug <path>For detailed output about paths and configuration:
./bin/uocs --debug <path>
./bin/uocbf --debug <path>- Fork the repository
- Create your feature branch
- Make your changes
- Run tests and ensure coding standards:
make check-standards
./bin/uocs .- Submit a pull request
MIT License - see LICENSE file for details.