ergebnis / license
Provides an abstraction of an open-source license.
Installs: 1 234 814
Dependents: 76
Suggesters: 0
Security: 0
Stars: 14
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: ~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0
- ext-filter: *
Requires (Dev)
- ergebnis/composer-normalize: ^2.44.0
- ergebnis/data-provider: ^3.3.0
- ergebnis/php-cs-fixer-config: ^6.37.0
- ergebnis/phpunit-slow-test-detector: ^2.16.1
- fakerphp/faker: ^1.24.0
- infection/infection: ~0.26.6
- phpstan/extension-installer: ^1.4.3
- phpstan/phpstan: ^1.12.10
- phpstan/phpstan-deprecation-rules: ^1.2.1
- phpstan/phpstan-phpunit: ^1.4.0
- phpstan/phpstan-strict-rules: ^1.6.1
- phpunit/phpunit: ^9.6.19
- rector/rector: ^1.2.10
- symfony/filesystem: ^5.4.41
This package is auto-updated.
Last update: 2024-11-18 16:36:25 UTC
README
This project provides a composer
package with an abstraction of an open-source license.
Installation
Run
composer require --dev ergebnis/license
Usage
Sometimes open source maintainers complain about the burden of managing an open-source project. Sometimes they argue that contributors opening pull requests to update license years unnecessarily increase their workload.
Of course, all of this can be automated, can't it?
Configuration for friendsofphp/php-cs-fixer
With friendsofphp/php-cs-fixer
you can use the configuration file .php-cs-fixer.php
to
- save the license to a file, e.g.
LICENSE
orLICENSE.md
- specify a file-level header using the
header_comment
fixer that will be replaced in PHP files
Here's an example of a .php-cs-fixer.php
file for an open-source project using the MIT
license type:
<?php declare(strict_types=1); /** * Copyright (c) 2020-2022 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/license */ use Ergebnis\License; use PhpCsFixer\Config; use PhpCsFixer\Finder; $license = License\Type\MIT::text( __DIR__ . '/LICENSE', License\Range::since( License\Year::fromString('2020'), new DateTimeZone('UTC') ), License\Holder::fromString('Andreas Möller'), License\Url::fromString('https://github.com/ergebnis/license') ); $license->save(); $finder = Finder::create()->in(__DIR__); return Config::create() ->setFinder($finder) ->setRules([ 'header_comment' => [ 'comment_type' => 'PHPDoc', 'header' => $license->header(), 'location' => 'after_declare_strict', 'separate' => 'both', ], ]);
💡 Also take a look at .php-cs-fixer.php
of this project.
Here's an example of a .php-cs-fixer.php
file for a closed-source project using the None
license type:
<?php declare(strict_types=1); /** * Copyright (c) 2011-2019 Andreas Möller * * @see https://github.com/localheinz/localheinz.com */ use Ergebnis\License; use PhpCsFixer\Config; use PhpCsFixer\Finder; $license = License\Type\None::text( License\Range::since( License\Year::fromString('2020'), new DateTimeZone('UTC') ), License\Holder::fromString('Andreas Möller'), License\Url::fromString('https://github.com/localheinz/localheinz.com') ); $finder = Finder::create()->in(__DIR__); return Config::create() ->setFinder($finder) ->setRules([ 'header_comment' => [ 'comment_type' => 'PHPDoc', 'header' => $license->header(), 'location' => 'after_declare_strict', 'separate' => 'both', ], ]);
GitHub Actions
When using GitHub Actions, you can set up a scheduled workflow that opens a pull request to the license year automatically on January 1st:
name: "License" on: schedule: - cron: "1 0 1 1 *" jobs: license: name: "License" runs-on: "ubuntu-latest" steps: - name: "Checkout" uses: "actions/checkout@v2.0.0" - name: "Install dependencies with composer" run: "composer install --no-interaction --no-progress --no-suggest" - name: "Run friendsofphp/php-cs-fixer" run: "vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --diff --dry-run --verbose" - name: "Open pull request updating license year" uses: "gr2m/create-or-update-pull-request-action@v1.2.9" with: author: "Andreas Möller <am@localheinz.com>" branch: "feature/license-year" body: | This PR - [x] updates the license year commit-message: "Enhancement: Update license year" path: "." title: "Enhancement: Update license year" env: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
💡 See crontab.guru
if you need help scheduling the workflow.
Note that pull requests opened or commits pushed by GitHub Actions will not trigger a build. As an alternative, you can set up a bot user:
- name: "Open pull request updating license year" uses: "gr2m/create-or-update-pull-request-action@v1.2.9" with: - author: "Andreas Möller <am@localheinz.com>" + author: "ergebnis-bot <bot@ergebn.is>" branch: "feature/license-year" body: | This PR - [x] updates the license year commit-message: "Enhancement: Update license year" path: "." title: "Enhancement: Update license year" env: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + GITHUB_TOKEN: "${{ secrets.ERGEBNIS_BOT_TOKEN }}"
Types
The following license types are currently available:
💡 Need a different license type? Feel free to open a pull request!
Changelog
The maintainers of this project record notable changes to this project in a changelog.
Contributing
The maintainers of this project suggest following the contribution guide.
Code of Conduct
The maintainers of this project ask contributors to follow the code of conduct.
General Support Policy
The maintainers of this project provide limited support.
You can support the maintenance of this project by sponsoring @localheinz or requesting an invoice for services related to this project.
PHP Version Support Policy
This project supports PHP versions with active and security support.
The maintainers of this project add support for a PHP version following its initial release and drop support for a PHP version when it has reached the end of security support.
Security Policy
This project has a security policy.
License
This project uses the MIT license.
Social
Follow @localheinz and @ergebnis on Twitter.