maslosoft / hedron
PHP source code class header applier
Installs: 5 712
Dependents: 10
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=8.2
- ext-json: *
- maslosoft/addendum: *
- maslosoft/cli-shared: *
- symfony/console: >=2.7 <7.0
- symfony/finder: >=2.7 <7.0
- symfony/yaml: >=2.7 <7.0
- zordius/lightncandy: ^1
Requires (Dev)
- maslosoft/sitcom: *
- roave/security-advisories: dev-latest
Suggests
- maslosoft/sitcom: Collect commands with signals
README
Maslosoft Hedron
PHP source code class header applier
Quick Install
composer require maslosoft/hedron
Documentation
Keeping class headers consitent
When developing projects, we ofter require that file containing PHP class should have some predefined comment header. This might include package information, licensing, homepage address etc.
Apply all at once
This tools provides facility to modify class headers in entire project in a safe way - using PHP Tokenizer, so that it will only modify file if it's 100% safe to change it.
Hedron helps you make your class headers up to date and consistent. It will apply predefined header to all files containing namespaced class definitions.
Instalation
composer require maslosoft/hedron --dev
Usage
Preview list of files to apply headers
vendor/bin/hedron preview
Display rendered template
vendor/bin/hedron show
Apply header to all class files.
Backup/commit your project before continue. This will write headers to files.
vendor/bin/hedron commit
Configuration
Configuration can be provided in yaml file .hedron.yml
in root of your project.
Hedron also uses composer.json
to make your config easier, or even unnessesary.
Here is how config might look like with example values (see .hedron.example.yml
):
# All paths are realtive to your project root
# Root path or paths with sources. If blank will use composer.autoload paths.
sources: ""
# Path to template file, if blank will use vendor/maslosoft/hedron/templates/default.html (no it's not html)
template: ""
# Filter configuration, by default empty. Below is some example filter.
filter:
whitelist:
include:
- app/*
exclude:
- app/cache/*
blacklist:
include:
- app/controllers/*
exclude:
- app/cache/CacheProvider.php
# Reserved
# This contains composer.json as array
composer: ""
tmp: ""
All of this configuration is available in template.
Template
Template uses handlebars as templating engine. It contains all data from .hedron.yml
and composer.json
.
Here is example, default template:
This software package is licensed under {{composer.license}} license.
@package {{composer.name}}
@licence {{composer.license}}
{{#each composer.authors}}
@copyright Copyright (c) {{name}} <{{email}}>
{{/each}}
{{#if composer.homepage}}@link {{composer.homepage}}{{/if}}
And after rendering it looks like that:
/**
* This software package is licensed under New BSD license.
*
* @package maslosoft/hedron
* @licence New BSD
*
* @copyright Copyright (c) Peter Maselkowski <pmaselkowski@gmail.com>
*
* @link http://maslosoft.com/hedron/
*/
Replacing
This script modifies source files en masse. For safety and robustness it uses native php tokenizer and replaces everything before namespace
token. Only that. If there is no namespace declaration file will not be modified.