-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
11 changed files
with
88 additions
and
137 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 |
---|---|---|
@@ -1,20 +1,9 @@ | ||
# Changelog | ||
|
||
All notable changes to `swisnl/phpstan-bitbucket` will be documented in this file. | ||
All notable changes to `swisnl/bitbucket-reports` will be documented in this file. | ||
|
||
Updates should follow the [Keep a CHANGELOG](https://keepachangelog.com/) principles. | ||
|
||
## [Unreleased] | ||
|
||
- Nothing | ||
|
||
## [0.2.0] - 2022-11-04 | ||
|
||
This release lists changes compared to [alxt/phpstan-bitbucket:0.1.0](https://github.com/modprobe/phpstan-bitbucket/releases/tag/v0.1.0). | ||
|
||
### Changed | ||
|
||
- Bumped minimum PHP version to 7.4 and add support for PHP 8. | ||
- Bumped dependencies. | ||
- This error formatter will now also report errors using the default table error formatter. | ||
- Changed package name to `swisnl/phpstan-bitbucket` and namespace to `Swis\PHPStan\ErrorFormatter`. |
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
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 |
---|---|---|
@@ -1,45 +1,24 @@ | ||
# PHPStan Bitbucket error formatter | ||
# Bitbucket reports | ||
|
||
[![Latest Version on Packagist][ico-version]][link-packagist] | ||
[![Software License][ico-license]](LICENSE.md) | ||
[![Buy us a tree][ico-treeware]][link-treeware] | ||
[![Total Downloads][ico-downloads]][link-downloads] | ||
[![Maintained by SWIS][ico-swis]][link-swis] | ||
|
||
This PHPStan error formatter will add annotations in Bitbucket, for example in pull requests, similar to the built-in GitHub formatting. | ||
Helper classes for Bitbucket reports. | ||
|
||
## Installation | ||
|
||
Via Composer | ||
|
||
```bash | ||
composer require --dev swisnl/phpstan-bitbucket | ||
composer require swisnl/bitbucket-reports | ||
``` | ||
|
||
If you also have [phpstan/extension-installer](https://github.com/phpstan/extension-installer) installed, then you're all set! | ||
|
||
<details> | ||
<summary>Manual installation</summary> | ||
|
||
If you don't want to use `phpstan/extension-installer`, include extension.neon in your project's PHPStan config: | ||
|
||
```neon | ||
includes: | ||
- vendor/swisnl/phpstan-bitbucket/extension.neon | ||
``` | ||
</details> | ||
|
||
## Usage | ||
|
||
To use this custom error formatter you need to run PHPStan with `--error-format=bitbucket` option. For example: | ||
```shell | ||
vendor/bin/phpstan analyse src -l8 --error-format=bitbucket | ||
``` | ||
|
||
## Screenshots | ||
|
||
![Annotations](img/annotations.png) | ||
![Report](img/report.png) | ||
This is a collection of helper classes for Bitbucket reports, used by several of our projects. Please refer to these projects for usage examples. | ||
|
||
## Changelog | ||
|
||
|
@@ -55,9 +34,9 @@ If you discover any security related issues, please email [email protected] inste | |
|
||
## Credits | ||
|
||
This package is a fork of [alxt/phpstan-bitbucket][link-fork] with some updates. | ||
This package contains files from [alxt/phpstan-bitbucket][link-fork]. | ||
|
||
- [Alexander Timmermann][link-author] | ||
- [Jasper Zonneveld][link-author] | ||
- [All Contributors][link-contributors] | ||
|
||
## License | ||
|
@@ -70,16 +49,16 @@ This package is [Treeware](https://treeware.earth). If you use it in production, | |
|
||
[SWIS][link-swis] is a web agency from Leiden, the Netherlands. We love working with open source software. | ||
|
||
[ico-version]: https://img.shields.io/packagist/v/swisnl/phpstan-bitbucket.svg?style=flat-square | ||
[ico-version]: https://img.shields.io/packagist/v/swisnl/bitbucket-reports.svg?style=flat-square | ||
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square | ||
[ico-treeware]: https://img.shields.io/badge/Treeware-%F0%9F%8C%B3-lightgreen.svg?style=flat-square | ||
[ico-downloads]: https://img.shields.io/packagist/dt/swisnl/phpstan-bitbucket.svg?style=flat-square | ||
[ico-downloads]: https://img.shields.io/packagist/dt/swisnl/bitbucket-reports.svg?style=flat-square | ||
[ico-swis]: https://img.shields.io/badge/%F0%9F%9A%80-maintained%20by%20SWIS-%230737A9.svg?style=flat-square | ||
|
||
[link-packagist]: https://packagist.org/packages/swisnl/phpstan-bitbucket | ||
[link-downloads]: https://packagist.org/packages/swisnl/phpstan-bitbucket | ||
[link-treeware]: https://plant.treeware.earth/swisnl/phpstan-bitbucket | ||
[link-packagist]: https://packagist.org/packages/swisnl/bitbucket-reports | ||
[link-downloads]: https://packagist.org/packages/swisnl/bitbucket-reports | ||
[link-treeware]: https://plant.treeware.earth/swisnl/bitbucket-reports | ||
[link-fork]: https://github.com/modprobe/phpstan-bitbucket | ||
[link-author]: https://github.com/modprobe | ||
[link-author]: https://github.com/JaZo | ||
[link-contributors]: ../../contributors | ||
[link-swis]: https://www.swis.nl |
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
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
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
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
This file was deleted.
Oops, something went wrong.
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,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Swis\Bitbucket\Reports; | ||
|
||
/** | ||
* Copied from https://github.com/phpstan/phpstan-src/blob/1.11.x/src/File/ParentDirectoryRelativePathHelper.php | ||
*/ | ||
class ParentDirectoryRelativePathHelper | ||
{ | ||
public function __construct(private string $parentDirectory) | ||
{ | ||
} | ||
|
||
public function getRelativePath(string $filename): string | ||
{ | ||
return implode('/', $this->getFilenameParts($filename)); | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getFilenameParts(string $filename): array | ||
{ | ||
$schemePosition = strpos($filename, '://'); | ||
if ($schemePosition !== \false) { | ||
$filename = substr($filename, $schemePosition + 3); | ||
} | ||
$parentParts = explode('/', trim(str_replace('\\', '/', $this->parentDirectory), '/')); | ||
$parentPartsCount = count($parentParts); | ||
$filenameParts = explode('/', trim(str_replace('\\', '/', $filename), '/')); | ||
$filenamePartsCount = count($filenameParts); | ||
$i = 0; | ||
for (; $i < $filenamePartsCount; $i++) { | ||
if ($parentPartsCount < $i + 1) { | ||
break; | ||
} | ||
$parentPath = implode('/', array_slice($parentParts, 0, $i + 1)); | ||
$filenamePath = implode('/', array_slice($filenameParts, 0, $i + 1)); | ||
if ($parentPath !== $filenamePath) { | ||
break; | ||
} | ||
} | ||
if ($i === 0) { | ||
return [$filename]; | ||
} | ||
$dotsCount = $parentPartsCount - $i; | ||
if ($dotsCount < 0) { | ||
throw new \RuntimeException('This should not happen.'); | ||
} | ||
|
||
return array_merge(array_fill(0, $dotsCount, '..'), array_slice($filenameParts, $i)); | ||
} | ||
} |