Modern PHP, TypeScript Philosophy, Maximum Confidence
Transform your PHP development with a coding standard that brings the best of TypeScript/ESLint ecosystem to PHP. NCAC enforces strict typing, explicit patterns, and consistent formatting for code that reads like poetry and runs with confidence.
Every parameter, return value, and property must be explicitly typed. No more guessing, no more runtime surprises.
// β Old way: ambiguous and error-prone
function process($data) {
return $data->value;
}
// β
NCAC way: crystal clear intent
function process(DataObject $data): string {
return $data->value;
}Revolutionary 2-space indentation with TypeScript-inspired array handling. Function arguments get special treatment for maximum readability.
// β
TypeScript-style function arguments
$result = my_function([
'clean' => 'readable',
'consistent' => 'beautiful'
]);
// β
Regular arrays maintain full indentation hierarchy
$config = [
'database' => [
'host' => 'localhost',
'port' => 3306
]
];Smart naming conventions that adapt to context: snake_case for variables and functions, camelCase for class properties and methods, PascalCase for classes.
// β
Context-aware naming in action
class UserRepository {
private string $connectionString; // camelCase property
public function findUser(int $user_id): User { // snake_case parameter
$query_result = $this->executeQuery($user_id); // snake_case variable
return $this->mapToUser($query_result); // camelCase method
}
}The NCAC standard reimagines PHP development through the lens of modern TypeScript practices:
- Mandatory type hints for parameters, returns, and properties
- Explicit visibility for all class constants and members
- Clear intent through naming conventions that tell a story
- 21 carefully curated rules that work together harmoniously
- Auto-fixable formatting means your code always looks professional
- IDE-first design for seamless development experience
- PHP 7.4+ features like typed properties and arrow functions
- Enum support for PHP 8.1+ with proper spacing
- Performance optimized sniffs that don't slow you down
- Fail fast with immediate feedback on type and style issues
- Smart defaults that rarely need customization
- Comprehensive documentation with real-world examples
composer require --dev ncac/phpcs-standard# Check your code
vendor/bin/phpcs --standard=NCAC src/
# Auto-fix issues
vendor/bin/phpcbf --standard=NCAC src/Create a phpcs.xml in your project root:
<?xml version="1.0"?>
<ruleset name="YourProject">
<description>Your project coding standard</description>
<rule ref="NCAC"/>
<!-- Your source directories -->
<file>src</file>
<file>tests</file>
<!-- Optional: Exclude specific rules if needed -->
<rule ref="NCAC">
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint"/>
</rule>
</ruleset>- π Complete Rules Reference - Detailed examples for all 21 rules
- π οΈ Development Setup Guide - VS Code Dev Container setup
- π€ Contributing Guidelines - How to contribute to the project
- π Known Issues - Current limitations and workarounds
- PHP 7.4+ typed properties fully supported
- PHP 8.0+ enums with proper spacing rules
- Auto-fixable rules for seamless workflow integration
- Performance optimized for large codebases
- IDE-first design works seamlessly with VS Code, PhpStorm
- Comprehensive test coverage ensures reliability
- Rich error messages guide you to the solution
- Minimal configuration required
- Smart indentation adapts to context (function args vs. standalone arrays)
- Consistent naming that scales across teams and projects
- Explicit typing catches errors before they reach production
- Modern formatting that's easy to read and maintain
class userRepository
{
function findUser($userId)
{
$queryResult = $this->executeQuery($userId);
if ($queryResult) {
return $queryResult;
}
return null;
}
private $connectionString;
const CACHE_TTL = 3600;
}class UserRepository {
private string $connectionString;
public const CACHE_TTL = 3600;
public function findUser(int $user_id): ?User {
$query_result = $this->executeQuery($user_id);
if ($query_result !== null) {
return $this->mapToUser($query_result);
}
return null;
}
}Modern software development is converging towards explicit typing, consistent patterns, and predictable behavior across all languages and platforms:
- TypeScript transformed JavaScript from chaos to confidence
- Swift brought type safety to mobile development
- Rust proved that safety and performance can coexist
- PHP 7.4+ embraced typed properties, union types, and strict typing
NCAC recognizes this historical trend and positions PHP as a first-class citizen in the modern development ecosystem. We're not just writing PHP codeβwe're writing future-proof, maintainable, and trustworthy software that scales with your business.
- Team Velocity: Developers familiar with TypeScript/ESLint can instantly read NCAC-compliant PHP
- Career Growth: Skills transfer seamlessly between languages
- Code Quality: Consistent patterns reduce cognitive load and bugs
- Tooling Integration: Modern IDEs and static analyzers work better with explicit types
"The languages that survive and thrive are those that embrace clarity over cleverness, explicitness over magic, and safety over shortcuts."
Disable specific rules for legacy codebases:
<!-- Gradually adopt NCAC -->
<rule ref="NCAC">
<!-- Disable strict typing for migration period -->
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint"/>
</rule>Customize Slevomat spacing rules (built-in configurability):
<!-- Adjust Slevomat spacing to your team preferences -->
<rule ref="SlevomatCodingStandard.Classes.MethodSpacing">
<properties>
<property name="minLinesCountBeforeWithComment" value="1"/>
<property name="maxLinesCountBeforeWithComment" value="1"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Classes.PropertySpacing">
<properties>
<property name="minLinesCountBeforeWithComment" value="1"/>
<property name="maxLinesCountBeforeWithComment" value="1"/>
</properties>
</rule>Note: NCAC custom sniffs (like
NCAC.Formatting.ClassClosingSpacing,NCAC.WhiteSpace.TwoSpacesIndent) are not yet configurable. This is planned for future releases.
-
Clone the repository:
git clone https://github.com/ncac/phpcs-standard.git cd phpcs-standard -
Generate environment (before opening in VS Code):
.docker/generate-env.sh
-
Open in VS Code: The Dev Container will automatically configure everything.
# Install dependencies
composer install
pnpm install
# Run full quality checks
vendor/bin/phing check
# Run specific checks
vendor/bin/psalm # Static analysis
vendor/bin/phpunit # Unit tests
vendor/bin/phpcs --standard=NCAC NCAC/ # Self-checkWe welcome contributions! Please see our Contributing Guidelines for:
- π Bug reports with reproducible examples
- β¨ Feature requests with clear use cases
- π§ Pull requests with comprehensive tests
- π Documentation improvements
The NCAC standard is built upon and deeply grateful to two foundational projects:
This project would not exist without PHP_CodeSniffer by Squiz Labs. PHP_CodeSniffer provides the robust tokenization engine, extensible architecture, and auto-fixing capabilities that make NCAC possible. We extend our heartfelt thanks to the maintainers and contributors of this essential PHP tool.
The NCAC standard incorporates and builds upon the excellent Slevomat Coding Standard, which provides many of the strict typing, documentation, and structural rules that define modern PHP development. The quality and comprehensiveness of Slevomat's work has been instrumental in shaping NCAC's approach to type safety and code organization.
While leveraging these proven foundations, NCAC adds 7 custom sniffs that implement:
- Revolutionary 2-space indentation with TypeScript-style array handling
- Context-aware naming conventions (snake_case variables, camelCase properties, PascalCase classes)
- Strict formatting rules for class structure and control flow
- Modern PHP patterns aligned with contemporary development practices
All custom rules are designed to complement (not replace) the existing ecosystem, ensuring maximum compatibility and adoption.
License Compliance: NCAC respects and operates under the licenses of all incorporated projects. See our LICENSE file for complete details.
- PHP: 7.4, 8.0, 8.1, 8.2, 8.3
- PHP_CodeSniffer: 3.7.0 or higher
- Composer: 2.0 or higher
- β 21 comprehensive rules covering all aspects of PHP code quality
- β Auto-fixable formatting for seamless workflow integration
- β Type safety enforcement with mandatory type hints
- β Modern PHP support including enums and typed properties
- β IDE integration for VS Code, PhpStorm, and others
- β Performance optimized for large codebases
- β Extensive test coverage ensuring reliability
- β Rich documentation with practical examples
- π Documentation Hub - Comprehensive guides and references
- π Issue Tracker - Bug reports and feature requests
- π¬ Discussions - Community Q&A and ideas
- π Releases - Version history and changelogs
This project is licensed under the MIT License - see the LICENSE file for details.
Ready to transform your PHP code? π
composer require --dev ncac/phpcs-standard
vendor/bin/phpcs --standard=NCAC src/