Download the PHP package crmplease/coder without Composer
On this page you can find all versions of the php package crmplease/coder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download crmplease/coder
More information about crmplease/coder
Files in crmplease/coder
Package coder
Short Description Coder is library for code-generation, e.g. add property to class, parameter to method, value to array and etc.
License MIT
Homepage https://github.com/crmplease/coder
Informations about the package coder
Coder
Coder is library for code-generation, e.g. add property to class, parameter to method, value to array and etc. Library is based on Rector.
Installation
This library should be installed as a dependency using Composer:
Get started
The facade class of this library is Coder
, you need to just create it and call methods, example:
API
In all methods value can be:
- int
- float
- string
- instance of
Constant
class (see below) - instance of
Code
class (see below) - array of arrays or types above with keys of types below
In all methods key can be:
- int
- string
- instance of
Constant
class (see below)
In all methods path is a path in array, if path not found, then it will be added. Path is array, so if we use path ['level1', 'level2']
, then empty array became:
Use empty path if you want to change root level in array.
Parts of the path can be same as key:
- int
- string
- instance of
Constant
class (see below)
If you need to pass code, which will be added as is, then you can use Code
class:
If you need to pass some constant, the you can use Constant
class :
Add to file return array by order
If value 'newValue'
already exists in array, then nothing changed.
Example:
Became:
Add to method return array by order
If value 'newValue'
already exists in array, then nothing changed.
Example:
Became:
Add to property array by order
If value 'newValue'
already exists in array, then nothing changed.
Example:
Became:
Add to file return array by key
If key 'newKey'
already exists in array, then value for this key will be changed to 'newValue'
.
Example:
Became:
Add to method return array by key
If key 'newKey'
already exists in array, then value for this key will be changed to 'newValue'
.
Example:
Became:
Add to property array by key
If key 'newKey'
already exists in array, then value for this key will be changed to 'newValue'
.
Example:
Became:
Add property to class
If property exists, then property will be updated.
Example:
Became:
Add parameter to method:
If parameter exists, then type will be checked. If it's different, then RectorException
will be thrown. If it's equal, then default value will be changed.
Example:
Became:
Add code to the end of method
In simple cases code duplicates is checked (when you try to add one line code).
Example:
Became:
Add method to class
If method exists, then signature and Phpdoc will be updated.
Example:
Became:
Add Phpdoc param to method
If Phpdoc for parameter already exists, then it will be removed and added again.
Example:
Became
Add Phpdoc property to class
If Phpdoc for property already exists, then it will be updated.
Example:
Became
You can add several properties:
Add Phpdoc method to class
If Phpdoc for method already exists, then it will be updated.
Example:
Became
You can add several methods:
Add trait to class
If trait is already used, then nothing will be changed.
Example:
Became:
Remove trait from class
If trait isn't used, then nothing will be changed.
Example:
Became:
Change class parent
If parent doesn't exists, then it will be added.
Example:
Became:
More complex example
More complex example with constants and code:
If value 'newValue'
already exists in array, then nothing changed.
Example:
Became:
Config
You can provide config object when create coder:
Disable progress bar
By default rector shows progress bar when change files. You can disable it:
Auto import classes
By default auto import classes is disabled by config/rector.php
. You can change default value or use mapping/callback for enable/disable auto import classes:
Path to rector config path
Rector config file for coder is config/rector.php
or add new one:
For more information about rector configuration see rector documentation.
Internals
If you want to auto import classes, then change parameters.auto_import_names
to true
in config/rector.php
.
You can run Rector using command line interface:
But command line interface doesn't allow to pass parameters to rectors. You can pass parameters using setters in config file config/rector.php
config. For example:
AddToFileReturnArrayByOrderRector
Config for AddToFileReturnArrayByOrderRector:
- setPath: path in array where need to add value
- setValue: value, which need to add to return array
AddToReturnArrayByOrderRector
Config for AddToReturnArrayByOrderRector:
- setMethod: method name, to which need to add value/constant to return array, method should have only one return statement, which return array
- setPath: path in array where need to add value
- setValue: value, which need to add to return array
AddToPropertyArrayByOrderRector
Config for AddToPropertyArrayByOrderRector:
- setProperty: property name, to which need to add value/constant, property should be array
- setPath: path in array where need to add value
- setValue: value, which need to add to return array
AddToFileReturnArrayByKeyRector
Config for AddToFileReturnArrayByKeyRector:
- setPath: path in array where need to add key => value
- setKey: key, by which need to add to return array
- setValue: value, which need to add to return array by key
AddToReturnArrayByKeyRector
Config for AddToReturnArrayByKeyRector:
- setMethod: method name, to which need to add value/constant to return array by key, method should have only one return statement, which return array
- setPath: path in array where need to add key => value
- setKey: key, by which need to add to return array
- setValue: value, which need to add to return array by key
AddToPropertyArrayByKeyRector
Config for AddToPropertyArrayByKeyRector:
- setProperty: property name, to which need to add value/constant by key, property should be array
- setPath: path in array where need to add key => value
- setKey: key, by which need to add to property array
- setValue: value, which need to add to property array by key
AddPropertyToClassRector
Config for AddPropertyToClassRector:
- setProperty: property name which need to add
- setVisibility: property visibility 'public', 'protected' or 'private', default is 'private'
- setIsStatic: is property static or no, true or false, default false
- setValue: default property value, don't pass it if isn't needed
- setType: property type in Phpdoc, can be class name started with '\' or scalar type, can by autodetected by default value
- setDescription: property description in Phpdoc
AddParameterToMethodRector
Config for AddParameterToMethodRector:
- setMethod: method name, to which need to add parameter
- setParameter: parameter name which need to add
- setParameterType: parameter type which need to add, can be class name started with '\' or scalar type
- setHasValue: has default value or not, true or false, default true
- setValue: default parameter value
AddCodeToMethodRector
Config for AddCodeToMethodRector:
- setMethod: method name, to which need to add code
- setCode: code which need to add
AddMethodToClassRector
Config for AddMethodToClassRector:
- setMethod: method name which need to add
- setVisibility: method visibility 'public', 'protected' or 'private', default is 'private'
- setIsStatic: is method static or no, true or false, default false
- setIsAbstract: is method abstract or no, true or false, default false
- setIsFinal: is method final or no, true or false, default false
- setReturnType: method return type, can be class name started with '\' or scalar type or void
- setReturnDescription: return description in Phpdoc
- setDescription: method description in Phpdoc
AddTraitToClassRector
Config for AddTraitToClassRector:
- setTrait: trait name, to which need to add to class
RemoveTraitFromClassRector
Config for RemoveTraitFromClassRector:
- setTrait: trait name, to which need to remove from class
AddPhpdocParamToMethodRector
Config for AddPhpdocParamToMethodRector:
- setMethod: method name, to which Phpdoc need to add parameter
- setParameter: parameter name which need to add to Phpdoc
- setParameterType: parameter type which need to add to Phpdoc, can be class name started with '\' or scalar type, collections, union type
- setDescription: description for param in Phpdoc
AddPhpdocPropertyToClassRector
Config for AddPhpdocPropertyToClassRector:
- setProperty: property name which need to add to Phpdoc
- setPropertyType: property type which need to add to Phpdoc, can be class name started with '\' or scalar type, collections, union type
- setDescription: description for property in Phpdoc
AddPhpdocMethodToClassRector
Config for AddPhpdocMethodToClassRector:
- setMethod: method name which need to add to Phpdoc
- setReturnType: method return type which need to add to Phpdoc, can be class name started with '\' or scalar type, collections, union type
- setIsStatic: is method static or no, true or false, default false
- setParameters: array of
PhpdocMethodParameter
objects - setDescription: description for method in Phpdoc
ChangeClassParentRector
Config for ChangeClassParentRector:
- setParentClass: new parent class name
All versions of coder with dependencies
nikic/php-parser Version ^4.10
phpstan/phpdoc-parser Version ^0.4.10
symfony/dependency-injection Version ^5.2
symplify/set-config-resolver Version ^9.1
symplify/smart-file-system Version ^9.1
symplify/package-builder Version ^9.1
symfony/console Version ^5.2