Skip to content

Introduce CodingStandardsStrategy for customizable naming conventions#602

Merged
veewee merged 1 commit intophpro:v5.xfrom
veewee:coding-standards
Feb 27, 2026
Merged

Introduce CodingStandardsStrategy for customizable naming conventions#602
veewee merged 1 commit intophpro:v5.xfrom
veewee:coding-standards

Conversation

@veewee
Copy link
Contributor

@veewee veewee commented Feb 27, 2026

Summary

  • Adds CodingStandardsStrategyInterface allowing users to customize how SOAP types, operations, namespaces, enum cases, and parameters are named in generated PHP code
  • Introduces CodeGeneratorContext value object that bundles TypeNamespaceMap + CodingStandardsStrategyInterface, replacing raw TypeNamespaceMap throughout the model/assembler/rule layers
  • Default behavior is unchanged (DefaultCodingStandardsStrategy delegates to existing Normalizer)
  • Generated config now uses return ($config = Config::create()) pattern so $config->getCodingStandards() is accessible in nested fluent calls

Example: PER-compatible coding standards

❗ It's just an example - You might need to change things.
Also consider that some SOAP services might have properties that resolve to the same name. For example your service can have 2 properties named: foo_bar and fooBar wich will both resolve to fooBar. This will cause conflicts. That's why we have our default coding strategy.

use Phpro\SoapClient\CodeGenerator\CodingStandards\CodingStandardsStrategyInterface;
use Phpro\SoapClient\CodeGenerator\CodingStandards\DefaultCodingStandardsStrategy;

final readonly class PerCodingStandards implements CodingStandardsStrategyInterface
{
    private DefaultCodingStandardsStrategy $default;

    public function __construct()
    {
        $this->default = new DefaultCodingStandardsStrategy();
    }

    public function normalizeTypeName(string $name): string
    {
        return $this->default->normalizeTypeName($name);
    }

    public function normalizeOperationName(string $name): string
    {
        return $this->default->normalizeOperationName($name);
    }

    public function normalizeNamespaceSegment(string $name): ?string
    {
        return $this->default->normalizeNamespaceSegment($name);
    }

    public function normalizeEnumCaseName(string $value): string
    {
        return $this->default->normalizeEnumCaseName($value);
    }

    public function generatePropertyAccessorMethodName(string $prefix, string $property): string
    {
        // PER: camelCase accessors based on camelCase parameter name
        return $prefix . ucfirst($this->normalizeParameterName($property));
    }

    public function normalizeParameterName(string $propertyName): string
    {
        // PER: camelCase parameters (e.g. "first_name" -> "firstName")
        return lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $propertyName))));
    }
}

Usage in config:

return ($config = Config::create())
    ->setCodingStandards(new PerCodingStandards())
    ->setEngine($engine = DefaultEngineFactory::create(
        EngineOptions::defaults('service.wsdl')
    ))
    ->setTypeNamespaceMap(
        TypeNamespaceMap::create(new Destination('src/Type', 'App\\Type'))
        ->withStrategy(new PrefixBasedTypeNamespaceStrategy($config->getCodingStandards()))
    )
    // ...

This generates $this->first_name = $firstName; and getFirstName() / withFirstName() accessors — keeping SOAP property names stable while using PER-compliant camelCase for parameters and methods.

@veewee veewee force-pushed the coding-standards branch 4 times, most recently from ba8e847 to a22a9ad Compare February 27, 2026 14:33
@veewee veewee marked this pull request as draft February 27, 2026 14:34
@veewee veewee changed the title Introduce CodingStandardsStrategy for customizable naming conventions [WIP] Introduce CodingStandardsStrategy for customizable naming conventions Feb 27, 2026
@veewee veewee requested a review from Copilot February 27, 2026 14:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a pluggable CodingStandardsStrategyInterface to let consumers customize how SOAP names (types, operations, namespaces, enum cases, parameters) are converted into generated PHP code, while preserving the existing behavior via DefaultCodingStandardsStrategy. It also centralizes codegen inputs via a new CodeGeneratorContext (bundling TypeNamespaceMap + coding standards) and updates generators/contexts/strategies to use it end-to-end.

Changes:

  • Add CodingStandardsStrategyInterface + DefaultCodingStandardsStrategy, and thread it through type/client/enum generation.
  • Introduce CodeGeneratorContext and replace many TypeNamespaceMap parameters with this unified context across model/assembler/rule layers.
  • Update config generation & documentation to support referencing $config->getCodingStandards() inside nested fluent calls.

Reviewed changes

Copilot reviewed 99 out of 99 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
test/PhproTest/SoapClient/Unit/Soap/Metadata/Manipulators/DuplicateTypes/RemoveDuplicateTypesStrategyTest.php Updates duplicate-type strategy tests to construct/use CodeGeneratorContext.
test/PhproTest/SoapClient/Unit/Soap/Metadata/Manipulators/DuplicateTypes/IntersectDuplicateTypesStrategyTest.php Updates intersect strategy tests for context-based API.
test/PhproTest/SoapClient/Unit/Soap/Metadata/Manipulators/DuplicateTypes/DuplicateTypesKeyTest.php Updates key generation tests to use context + namespaces in key.
test/PhproTest/SoapClient/Unit/CodeGenerator/TypeNamespaceMap/Strategy/PrefixBasedTypeNamespaceStrategyTest.php Adds tests for custom coding-standards usage in namespace strategy.
test/PhproTest/SoapClient/Unit/CodeGenerator/Provider/ScalarDefaultProviderTest.php Updates Property::fromMetaData() calls to accept CodeGeneratorContext.
test/PhproTest/SoapClient/Unit/CodeGenerator/Model/PropertyTest.php Updates Property construction/helpers for CodeGeneratorContext.
test/PhproTest/SoapClient/Unit/CodeGenerator/EnumerationGeneratorTest.php Updates enum generator tests to use context-based Type.
test/PhproTest/SoapClient/Unit/CodeGenerator/ConfigurationHelper.php Adds helper to create CodeGeneratorContext for tests.
test/PhproTest/SoapClient/Unit/CodeGenerator/ConfigGeneratorTest.php Updates expected generated config to return ($config = Config::create()) pattern.
test/PhproTest/SoapClient/Unit/CodeGenerator/CodingStandards/DefaultCodingStandardsStrategyTest.php New unit tests for default coding standards behavior.
test/PhproTest/SoapClient/Unit/CodeGenerator/ClientFactoryGeneratorTest.php Updates classmap/type map setup to pass CodeGeneratorContext.
test/PhproTest/SoapClient/Unit/CodeGenerator/Assembler/UseAssemblerTest.php Updates assembler context construction to include CodeGeneratorContext.
test/PhproTest/SoapClient/Unit/CodeGenerator/Assembler/TraitAssemblerTest.php Updates TypeContext construction to include context.
test/PhproTest/SoapClient/Unit/CodeGenerator/Assembler/SetterAssemblerTest.php Updates property contexts + constructor helpers to pass context.
test/PhproTest/SoapClient/Unit/CodeGenerator/Assembler/ResultProviderAssemblerTest.php Updates TypeContext creation to include context.
test/PhproTest/SoapClient/Unit/CodeGenerator/Assembler/ResultAssemblerTest.php Updates context usage for result type generation tests.
test/PhproTest/SoapClient/Unit/CodeGenerator/Assembler/RequestAssemblerTest.php Updates context usage for request type generation tests.
test/PhproTest/SoapClient/Unit/CodeGenerator/Assembler/PropertyAssemblerTest.php Updates property/type contexts to carry CodeGeneratorContext.
test/PhproTest/SoapClient/Unit/CodeGenerator/Assembler/JsonSerializableAssemblerTest.php Updates TypeContext creation to include context.
test/PhproTest/SoapClient/Unit/CodeGenerator/Assembler/IteratorAssemblerTest.php Updates helper to return TypeContext with context.
test/PhproTest/SoapClient/Unit/CodeGenerator/Assembler/InterfaceAssemblerTest.php Updates property/type contexts to include CodeGeneratorContext.
test/PhproTest/SoapClient/Unit/CodeGenerator/Assembler/ImmutableSetterAssemblerTest.php Updates immutable setter tests for context-aware property/parameter naming.
test/PhproTest/SoapClient/Unit/CodeGenerator/Assembler/GetterAssemblerTest.php Updates getter tests to use context for method naming.
test/PhproTest/SoapClient/Unit/CodeGenerator/Assembler/FluentSetterAssemblerTest.php Updates fluent setter tests for context-aware parameter naming.
test/PhproTest/SoapClient/Unit/CodeGenerator/Assembler/FinalClassAssemblerTest.php Updates type context creation to include context.
test/PhproTest/SoapClient/Unit/CodeGenerator/Assembler/ExtendingTypeAssemblerTest.php Updates TypeContext construction to include context.
test/PhproTest/SoapClient/Unit/CodeGenerator/Assembler/ExtendAssemblerTest.php Updates type/property creation to use CodeGeneratorContext.
test/PhproTest/SoapClient/Unit/CodeGenerator/Assembler/ConstructorAssemblerTest.php Updates constructor assembly tests for renamed parameter generation.
test/PhproTest/SoapClient/Unit/CodeGenerator/Assembler/ClientMethodAssemblerTest.php Updates client method contexts to include CodeGeneratorContext.
test/PhproTest/SoapClient/Unit/CodeGenerator/Assembler/ClassMapAssemblerTest.php Updates classmap context to include CodeGeneratorContext.
test/PhproTest/SoapClient/Unit/CodeGenerator/Assembler/AbstractClassAssemblerTest.php Updates type context creation to include context.
src/Phpro/SoapClient/Soap/Metadata/Manipulators/DuplicateTypes/RemoveDuplicateTypesStrategy.php Switches duplicate-removal logic to accept CodeGeneratorContext.
src/Phpro/SoapClient/Soap/Metadata/Manipulators/DuplicateTypes/IntersectDuplicateTypesStrategy.php Switches duplicate-intersection logic to accept CodeGeneratorContext.
src/Phpro/SoapClient/Soap/Metadata/Manipulators/DuplicateTypes/DuplicateTypesKey.php Generates duplicate keys using coding standards + namespace map from context.
src/Phpro/SoapClient/Soap/Metadata/Detector/DuplicateTypeNamesDetector.php Uses coding standards strategy for type name normalization.
src/Phpro/SoapClient/Console/Command/GenerateTypesCommand.php Uses Config::getCodeGeneratorContext() for type map creation.
src/Phpro/SoapClient/Console/Command/GenerateClientFactoryCommand.php Wires context into TypeMap and ClassMapContext.
src/Phpro/SoapClient/Console/Command/GenerateClientCommand.php Uses context for client method map creation.
src/Phpro/SoapClient/Console/Command/GenerateClassmapCommand.php Uses context for type map creation during classmap generation.
src/Phpro/SoapClient/CodeGenerator/TypeNamespaceMap/Strategy/PrefixBasedTypeNamespaceStrategy.php Normalizes namespace segments via CodingStandardsStrategyInterface.
src/Phpro/SoapClient/CodeGenerator/TypeGenerator.php Passes CodeGeneratorContext into TypeContext/PropertyContext.
src/Phpro/SoapClient/CodeGenerator/Rules/IsResultRule.php Uses coding standards from context when matching response types.
src/Phpro/SoapClient/CodeGenerator/Rules/IsRequestRule.php Uses coding standards from context when matching request types.
src/Phpro/SoapClient/CodeGenerator/Rules/IsExtendingTypeRule.php Uses coding standards from context when listing extending types.
src/Phpro/SoapClient/CodeGenerator/Rules/IsAbstractTypeRule.php Uses coding standards from context when listing abstract types.
src/Phpro/SoapClient/CodeGenerator/Model/TypeMap.php Replaces stored TypeNamespaceMap with CodeGeneratorContext.
src/Phpro/SoapClient/CodeGenerator/Model/Type.php Uses coding standards for type naming and context for namespace detection.
src/Phpro/SoapClient/CodeGenerator/Model/ReturnType.php Uses context for namespace detection and coding standards for type names.
src/Phpro/SoapClient/CodeGenerator/Model/Property.php Adds coding-standards-backed methodName() / parameterName() helpers.
src/Phpro/SoapClient/CodeGenerator/Model/Parameter.php Uses context for namespace detection and coding standards for type names.
src/Phpro/SoapClient/CodeGenerator/Model/ClientMethodMap.php Accepts CodeGeneratorContext when building methods from metadata.
src/Phpro/SoapClient/CodeGenerator/Model/ClientMethod.php Stores CodeGeneratorContext and threads it to parameters/return type.
src/Phpro/SoapClient/CodeGenerator/EnumerationGenerator.php Normalizes enum names/cases via coding standards strategy.
src/Phpro/SoapClient/CodeGenerator/Context/TypeContext.php Adds CodeGeneratorContext to the context object API.
src/Phpro/SoapClient/CodeGenerator/Context/PropertyContext.php Adds CodeGeneratorContext to the context object API.
src/Phpro/SoapClient/CodeGenerator/Context/CodeGeneratorContext.php New value object bundling namespace map + coding standards strategy.
src/Phpro/SoapClient/CodeGenerator/Context/ClientMethodContext.php Adds CodeGeneratorContext to the context object API.
src/Phpro/SoapClient/CodeGenerator/Context/ClassMapContext.php Adds CodeGeneratorContext to the context object API.
src/Phpro/SoapClient/CodeGenerator/ConfigGenerator.php Generates config using $config = Config::create() to reference coding standards.
src/Phpro/SoapClient/CodeGenerator/Config/Config.php Adds coding standards config + provides getCodeGeneratorContext().
src/Phpro/SoapClient/CodeGenerator/CodingStandards/DefaultCodingStandardsStrategy.php New default strategy delegating to existing Normalizer.
src/Phpro/SoapClient/CodeGenerator/CodingStandards/CodingStandardsStrategyInterface.php New interface defining customizable naming hooks.
src/Phpro/SoapClient/CodeGenerator/ClientGenerator.php Creates ClientMethodContext with the CodeGeneratorContext.
src/Phpro/SoapClient/CodeGenerator/ClassMapGenerator.php Creates ClassMapContext with TypeMap’s CodeGeneratorContext.
src/Phpro/SoapClient/CodeGenerator/Assembler/SetterAssembler.php Uses Property::methodName() and Property::parameterName() for setters.
src/Phpro/SoapClient/CodeGenerator/Assembler/ImmutableSetterAssembler.php Uses context-aware property method/parameter naming for immutables.
src/Phpro/SoapClient/CodeGenerator/Assembler/GetterAssembler.php Uses Property::methodName() for getter method naming.
src/Phpro/SoapClient/CodeGenerator/Assembler/FluentSetterAssembler.php Uses context-aware parameter naming in fluent setters.
src/Phpro/SoapClient/CodeGenerator/Assembler/ExtendingTypeAssembler.php Uses coding standards for extended type name normalization.
src/Phpro/SoapClient/CodeGenerator/Assembler/ConstructorAssembler.php Uses Property::parameterName() for constructor parameter naming.
src/Phpro/SoapClient/CodeGenerator/Assembler/ClientMethodAssembler.php Uses coding standards for SOAP operation → PHP method normalization.
spec/Phpro/SoapClient/CodeGenerator/TypeGeneratorSpec.php Updates specs to pass CodeGeneratorContext through models/contexts.
spec/Phpro/SoapClient/CodeGenerator/Rules/TypenameMatchesRuleSpec.php Updates rule specs for new context constructor signature.
spec/Phpro/SoapClient/CodeGenerator/Rules/TypeMapRuleSpec.php Updates rule specs for CodeGeneratorContext propagation.
spec/Phpro/SoapClient/CodeGenerator/Rules/PropertynameMatchesRuleSpec.php Updates rule specs for context-aware property construction.
spec/Phpro/SoapClient/CodeGenerator/Rules/IsResultRuleSpec.php Updates specs for context-aware request/result matching.
spec/Phpro/SoapClient/CodeGenerator/Rules/IsRequestRuleSpec.php Updates specs for context-aware request/result matching.
spec/Phpro/SoapClient/CodeGenerator/Rules/IsExtendingTypeRuleSpec.php Updates specs for context-aware extending type matching.
spec/Phpro/SoapClient/CodeGenerator/Rules/IsAbstractTypeRuleSpec.php Updates specs for context-aware abstract type matching.
spec/Phpro/SoapClient/CodeGenerator/Rules/ClientMethodMatchesRuleSpec.php Updates client method specs to include CodeGeneratorContext.
spec/Phpro/SoapClient/CodeGenerator/Model/TypeSpec.php Updates model specs for context-aware type construction.
spec/Phpro/SoapClient/CodeGenerator/Model/TypeMapSpec.php Updates model specs for context-aware type map construction.
spec/Phpro/SoapClient/CodeGenerator/Model/ReturnTypeSpec.php Updates return type specs for context-aware construction.
spec/Phpro/SoapClient/CodeGenerator/Model/PropertySpec.php Updates property specs for context-aware construction.
spec/Phpro/SoapClient/CodeGenerator/Model/ParameterSpec.php Updates parameter specs for context-aware construction.
spec/Phpro/SoapClient/CodeGenerator/Model/ClientMethodSpec.php Updates client method specs to use CodeGeneratorContext.
spec/Phpro/SoapClient/CodeGenerator/Context/TypeContextSpec.php Updates context specs for new constructor signature.
spec/Phpro/SoapClient/CodeGenerator/Context/PropertyContextSpec.php Updates context specs for new constructor signature.
spec/Phpro/SoapClient/CodeGenerator/Context/ClientMethodContextSpec.php Updates context specs for new constructor signature.
spec/Phpro/SoapClient/CodeGenerator/Context/ClientFactoryContextSpec.php Updates factory context setup to use CodeGeneratorContext.
spec/Phpro/SoapClient/CodeGenerator/Context/ClassMapContextSpec.php Updates classmap context setup to use CodeGeneratorContext.
spec/Phpro/SoapClient/CodeGenerator/ClientGeneratorSpec.php Updates client generator specs to use CodeGeneratorContext.
spec/Phpro/SoapClient/CodeGenerator/ClassMapGeneratorSpec.php Updates classmap generator spec to pass CodeGeneratorContext into TypeMap::fromMetadata().
docs/drivers/metadata.md Updates docs to describe duplicate strategies receiving CodeGeneratorContext.
docs/code-generation/rules.md Documents new ClientMethodContext + context access (needs accuracy check).
docs/code-generation/configuration.md Updates configuration examples for $config + coding standards usage.
docs/code-generation/coding-standards.md New documentation explaining coding standards customization.
docs/code-generation/assemblers.md Documents ClientMethodContext + context access (needs accuracy check).
UPGRADING.md Updates upgrade guide for coding standards + context-based APIs (contains strategy example mismatch).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  Add CodingStandardsStrategyInterface to allow users to customize naming
  conventions for generated code (type names, method names, namespace
  segments, enum cases, property accessors, parameter names).

  Introduce CodeGeneratorContext as a value object bundling TypeNamespaceMap
  and CodingStandardsStrategyInterface, replacing TypeNamespaceMap as the
  configuration carrier through models, contexts, assemblers, and rules.
@veewee veewee changed the title [WIP] Introduce CodingStandardsStrategy for customizable naming conventions Introduce CodingStandardsStrategy for customizable naming conventions Feb 27, 2026
@veewee veewee marked this pull request as ready for review February 27, 2026 15:05
@veewee veewee merged commit 602b289 into phpro:v5.x Feb 27, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants