-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e046ca6
Showing
25 changed files
with
670 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/.gitattributes export-ignore | ||
/.gitlab-ci.yml export-ignore | ||
/build export-ignore | ||
/docs | ||
/phpcs.xml.dist export-ignore | ||
/phpmd.xml.dist export-ignore | ||
/phpunit.xml.dist export-ignore | ||
/phpstan.neon.dist export-ignore | ||
/phpmd.xml.dist export-ignore | ||
/tests export-ignore | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/.phpunit.result.cache | ||
/.phpunit.cache | ||
/build/ | ||
/vendor/ | ||
/code-climate.json | ||
/composer.lock | ||
/phpcs.xml | ||
/phpmd.xml | ||
/phpstan.json | ||
/phpstan.neon | ||
/phpunit.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# set the default docker image | ||
image: registry.gitlab.com/tjvb/phpimages:php80 | ||
|
||
stages: | ||
- prepare # prepare the cache | ||
- check # check the codestyles | ||
- test | ||
|
||
prepare_cache: | ||
stage: prepare | ||
script: | ||
# Install composer | ||
- curl -sS https://getcomposer.org/installer | php | ||
- php composer.phar validate | ||
- php composer.phar install | ||
# we use this artifact for all the jobs | ||
artifacts: | ||
name: "vendor" | ||
paths: | ||
- vendor/* | ||
|
||
lint: | ||
stage: check | ||
script: | ||
# lint recursive | ||
- find src/ -type f -name '*.php' -exec php -l {} \; | (! grep -v "No syntax errors detected" ) | ||
dependencies: [] | ||
|
||
phpcs: | ||
stage: check | ||
script: | ||
- vendor/bin/phpcs | ||
dependencies: | ||
- prepare_cache | ||
needs: | ||
- prepare_cache | ||
|
||
phpmd: | ||
stage: check | ||
script: | ||
- vendor/bin/phpmd src/ text phpmd.xml.dist | ||
dependencies: | ||
- prepare_cache | ||
needs: | ||
- prepare_cache | ||
|
||
phpstan: | ||
stage: check | ||
script: | ||
# check for phpstan errors | ||
- php -d memory_limit=500M vendor/bin/phpstan analyse --error-format=gitlab > phpstan.json | ||
- cat phpstan.json | ||
dependencies: | ||
- prepare_cache | ||
needs: | ||
- prepare_cache | ||
artifacts: | ||
paths: | ||
- phpstan.json | ||
when: always | ||
|
||
test_lowest: | ||
stage: test | ||
script: | ||
# Install composer | ||
- rm -f composer.lock | ||
- curl -sS https://getcomposer.org/installer | php | ||
- php composer.phar update --prefer-lowest | ||
- vendor/bin/phpunit --coverage-text --colors=never --log-junit=phpunitresult/junit.xml | ||
artifacts: | ||
reports: | ||
junit: phpunitresult/junit.xml | ||
dependencies: | ||
- prepare_cache | ||
needs: | ||
- prepare_cache | ||
|
||
test_php80: | ||
stage: test | ||
script: | ||
- vendor/bin/phpunit --coverage-text --colors=never --coverage-cobertura=phpunitresult/cobertura-coverage.xml --log-junit=phpunitresult/junit.xml | ||
- sed -i 's~ filename="~ filename="src/~' phpunitresult/cobertura-coverage.xml | ||
artifacts: | ||
reports: | ||
junit: phpunitresult/junit.xml | ||
cobertura: phpunitresult/cobertura-coverage.xml | ||
dependencies: | ||
- prepare_cache | ||
needs: | ||
- prepare_cache | ||
|
||
CodeQuality: | ||
stage: Code quality converter | ||
dependencies: | ||
- phpstan | ||
script: | ||
- vendor/bin/converter convert --phpstan --phpstan-json-file=phpstan.json | ||
artifacts: | ||
reports: | ||
codequality: code-climate.json | ||
when: always |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) | ||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). | ||
|
||
|
||
## [Unreleased] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Contributing | ||
Contributions are allways very welcome. This file is a guideline about how to contribute. | ||
|
||
## How to contribute | ||
All the contributes need to be done with a merge request. It is possible to create a merge request prefixed with WIP: to ask for feedback or if you didn't know how to match all requirements. | ||
Please be sure to check all the [requirements](#requirements) before sending your merge request (except a WIP merge request) | ||
|
||
## Requirements | ||
* All the code need to confirm to the [PSR-12](https://www.php-fig.org/psr/psr-12/). You can check this localy with `vendor/bin/phpcs` | ||
* We use [PHPMD](https://phpmd.org) to validate the quality of the code. You can check it localy with `vendor/bin/phpmd src text phpmd.xml.dist` | ||
* Add tests for code changes, we use [PHPUnit](https://phpunit.de/). You can run the test with `vendor/bin/phpunit` this wil also generate some reports in the build directory. | ||
* We also use [PHPStan](https://phpstan.org/) to find possible bugs in the code. You can run it with `vendor/bin/phpstan`. | ||
* Document the changes, any functional change or bug fix need to be writen in [CHANGELOG.md](CHANGELOG.md). Depending on your change you need to add some documentation to the [README.md](README.md) | ||
* Respect [SemVer](http://semver.org/), we use Semanting Versioning so please respect it with the changes you want to add. | ||
* A merge request for a change. Please don't mix multiple changes in one merge request. | ||
* Ask questions, if you are not sure about something ask it. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
MIT License | ||
Copyright (c) 2021 Tobias van Beek | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# GitHash | ||
|
||
This package is intended to give a usefull option | ||
|
||
|
||
## Examples | ||
See docs/examples for examples about how to use this package. | ||
|
||
|
||
## Installation | ||
You can install this package with composer by executing the command: `composer require tjvb/githash`. | ||
|
||
|
||
## Changelog | ||
We (try to) document all the changes in [CHANGELOG](CHANGELOG.md) so read it for more information. | ||
|
||
## Contributing | ||
You are very welcome to contribute, read about it in [CONTRIBUTING](CONTRIBUTING.md) | ||
|
||
## License | ||
The MIT License (MIT). Please see [License File](LICENSE.md) for more information. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"name": "tjvb/githash", | ||
"type": "library", | ||
"description": "Get the current git hash from your project.", | ||
"keywords": [ | ||
"tjvb", | ||
"githash" | ||
], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Tobias van Beek", | ||
"email": "t.vanbeek@tjvb.nl", | ||
"homepage": "https://www.tjvb.nl" | ||
} | ||
], | ||
"require": { | ||
"php": "^8.0" | ||
}, | ||
"require-dev": { | ||
"beechit/json-to-code-climate-subset-converter": "^1.6", | ||
"fakerphp/faker": "^1.15", | ||
"phpmd/phpmd": "^2.10", | ||
"phpstan/phpstan": "^0.12.94", | ||
"phpunit/phpunit": "^9.5", | ||
"squizlabs/php_codesniffer": "^3.6", | ||
"symfony/process": "^5.3" | ||
}, | ||
"suggest": { | ||
"symfony/process": "Used rather than `shell_exec` if available (tested with ^5.3)." | ||
}, | ||
"config": { | ||
"sort-packages": true | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"TJVB\\GitHash\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"TJVB\\GitHash\\Tests\\": "tests/" | ||
} | ||
}, | ||
"scripts": { | ||
"format": "vendor/bin/phpcbf", | ||
"test": "vendor/bin/phpunit --no-coverage", | ||
"test-coverage": "vendor/bin/phpunit --coverage-html coverage" | ||
}, | ||
"support": { | ||
"issues": "https://gitlab.com/tjvb/githash/-/issues", | ||
"source": "https://gitlab.com/tjvb/githash/-/tree/master" | ||
}, | ||
"funding": [ | ||
{ | ||
"type": "paypal", | ||
"url": "https://paypal.me/tvbeek" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
use TJVB\GitHash\Exceptions\GitHashException; | ||
use TJVB\GitHash\Factories\GitHashFinderFactory; | ||
use TJVB\GitHash\Retriever\Retriever; | ||
|
||
require_once 'vendor/autoload.php'; | ||
|
||
// we take the root from the project as example path | ||
$path = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR; | ||
|
||
/** | ||
* This example use the default finder factory with the default finders to see a very basic option | ||
*/ | ||
try { | ||
$retriever = Retriever::getWithFactory(GitHashFinderFactory::withDefaultFinders()); | ||
echo $retriever->getHash($path)->hash() . PHP_EOL; | ||
} catch (GitHashException $exception) { | ||
echo 'Failed to get the hash ' . $exception->getMessage() . PHP_EOL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0"?> | ||
<ruleset name="GitHash"> | ||
<description>The coding standard for GitHash.</description> | ||
<file>./src/</file> | ||
<file>./tests/</file> | ||
<arg name="extensions" value="php"/> | ||
|
||
<rule ref="PSR12"> | ||
</rule> | ||
<rule ref="Generic.PHP.ForbiddenFunctions"> | ||
<properties> | ||
<property name="forbiddenFunctions" type="array" value="sizeof=>count,delete=>unset,print_r=>null,var_dump=>null,exit=>null"/> | ||
</properties> | ||
</rule> | ||
</ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ruleset name="GitHash PHPMD ruleset" | ||
xmlns="http://pmd.sf.net/ruleset/1.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" | ||
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"> | ||
<description> | ||
GitHash ruleset | ||
</description> | ||
<rule ref="rulesets/design.xml" /> | ||
<rule ref="rulesets/codesize.xml" /> | ||
<rule ref="rulesets/controversial.xml" /> | ||
<rule ref="rulesets/naming.xml" /> | ||
<rule ref="rulesets/unusedcode.xml" /> | ||
</ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
parameters: | ||
level: 5 | ||
paths: | ||
- src | ||
- tests | ||
|
||
ignoreErrors: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
cacheResultFile=".phpunit.cache/test-results" | ||
executionOrder="depends,defects" | ||
beStrictAboutCoversAnnotation="true" | ||
beStrictAboutOutputDuringTests="true" | ||
beStrictAboutTodoAnnotatedTests="true" | ||
failOnRisky="true" | ||
failOnWarning="true" | ||
verbose="true"> | ||
<testsuites> | ||
<testsuite name="default"> | ||
<directory suffix="Test.php">tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<logging> | ||
<junit outputFile="build/junit.xml"/> | ||
<teamcity outputFile="build/teamcity.txt"/> | ||
<testdoxHtml outputFile="build/testdox/testdox.html"/> | ||
<testdoxText outputFile="build/testdox/testdox.txt"/> | ||
</logging> | ||
|
||
<coverage cacheDirectory=".phpunit.cache/code-coverage" | ||
processUncoveredFiles="true"> | ||
<include> | ||
<directory suffix=".php">src</directory> | ||
</include> | ||
|
||
<report> | ||
<clover outputFile="build/logs/clover.xml"/> | ||
<crap4j outputFile="build/coverage.crap4j.xml"/> | ||
<html outputDirectory="build/coverage"/> | ||
<php outputFile="build/coverage.php"/> | ||
<text outputFile="build/coverage.txt"/> | ||
</report> | ||
</coverage> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TJVB\GitHash\Contracts; | ||
|
||
interface FinderFactory | ||
{ | ||
public function register(GitHashFinder $finder): void; | ||
public function registerDefaultFinders(): void; | ||
public function getRegisteredFinders(): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TJVB\GitHash\Contracts; | ||
|
||
use TJVB\GitHash\Exceptions\GitHashException; | ||
use TJVB\GitHash\Values\GitHash; | ||
|
||
interface GitHashFinder | ||
{ | ||
/** | ||
* @param string $path | ||
* | ||
* @return GitHash | ||
* | ||
* @throws GitHashException | ||
*/ | ||
public function findHash(string $path): GitHash; | ||
|
||
public function isAvailable(): bool; | ||
} |
Oops, something went wrong.