Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The journey towards new CI #53

Merged
merged 6 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: phpstan

on:
push:
paths-ignore:
- 'Docs/**'
pull_request:
paths-ignore:
- 'Docs/**'


jobs:
phpstan:
name: phpstan

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
coverage: none

- name: Get Composer cache directory
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: PHPStan
run: vendor/bin/phpstan analyse --no-ansi --no-progress -c phpstan.neon
48 changes: 48 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Tests

on:
push:
paths-ignore:
- 'Docs/**'
pull_request:
paths-ignore:
- 'Docs/**'

jobs:
tests:
strategy:
fail-fast: true
matrix:
php: ["7.3", "7.4", "8.0", "8.1", "8.2", "8.3"]

name: "PHP ${{ matrix.php }}"

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
coverage: none
kadet1090 marked this conversation as resolved.
Show resolved Hide resolved

- name: Get Composer cache directory
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: PHPUnit
run: ./vendor/bin/phpunit
17 changes: 0 additions & 17 deletions .scrutinizer.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Docs/1-installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ next: 2-basic-usage

# Installation as library

First off, you need to have at least PHP 7.1.3, and [composer] installed, and then you can install
First off, you need to have at least PHP 7.3, and [composer] installed, and then you can install
KeyLighter into your project by simply executing:

```bash
Expand Down
4 changes: 2 additions & 2 deletions Language/GreedyLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private function _tokens($source, $offset = 0, $additional = [], $embedded = fal
{
$result = new UnprocessedTokens();

/** @var Language $language */
/** @var Rule $rule */
foreach ($this->_rules($embedded) as $rule) {
foreach ($rule->match($source) as $token) {
$result->add($token, $offset);
Expand Down Expand Up @@ -174,7 +174,7 @@ private function _rules($embedded = false)
*
* @param $embedded
*
* @return Rule|Rule[]
* @return Rule|Rule[]|array<string, array<int, Rule>>
*/
public function getEnds($embedded = false)
{
Expand Down
3 changes: 1 addition & 2 deletions Language/Php.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ function (
$match,
TokenFactoryInterface $factory
) use (
$annotationNameRule,
$allowedInAttributes
$annotationNameRule
) {
yield $factory->create(
Token::NAME,
Expand Down
4 changes: 2 additions & 2 deletions Matcher/RegexMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class RegexMatcher implements MatcherInterface
/**
* RegexMatcher constructor.
*
* @param $regex
* @param array|null $groups
* @param $regex
* @param array $groups
*/
public function __construct($regex, array $groups = [1 => null])
{
Expand Down
4 changes: 2 additions & 2 deletions Matcher/WordMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ public function __construct(array $words, array $options = [])

public function merge(array $words)
{
return new static(array_merge($this->words, $words), $this->options);
return new self(array_merge($this->words, $words), $this->options);
}

public function subtract(array $words)
{
return new static(array_diff($this->words, $words), $this->options);
return new self(array_diff($this->words, $words), $this->options);
}

public function getWords()
Expand Down
4 changes: 2 additions & 2 deletions Parser/DelegateTokenFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class DelegateTokenFactory implements TokenFactoryInterface
/**
* DelegateTokenFactory constructor.
*
* @param callable (TokenFactoryInterface $factory, array $params) $function
* @param TokenFactoryInterface|null $factory
* @param callable(TokenFactoryInterface, array $params): (Token|null) $function
* @param TokenFactoryInterface|null $factory
*/
public function __construct(callable $function, TokenFactoryInterface $factory = null)
{
Expand Down
2 changes: 1 addition & 1 deletion Parser/OpenRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class OpenRule extends Rule
/**
* @param $source
*
* @return Token[]
* @return Token[]|iterable<Token>
kadet1090 marked this conversation as resolved.
Show resolved Hide resolved
*/
public function match($source)
{
Expand Down
8 changes: 4 additions & 4 deletions Parser/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*
* @package Kadet\Highlighter\Parser
*
* @property Language $language
* @property Language|false|null $language
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if null is really a supported value here. The default value for the option is false and if null is not supported then we have to fix the condition in

if ($lang === null && $this->inject !== $context->language) {
to compare against false instead (or use empty())

* @property Language $inject
* @property integer $priority
* @property string $type
Expand All @@ -40,7 +40,7 @@
class Rule
{
/**
* @var Validator
* @var Validator|false
*/
public $validator = false;
private $_matcher;
Expand Down Expand Up @@ -106,7 +106,7 @@ public function setMatcher(MatcherInterface $matcher)
/**
* @param $source
*
* @return Token[]|\Iterator
* @return iterable<Token>|\Iterator
*/
public function match($source)
{
Expand All @@ -120,7 +120,7 @@ public function __get($option)

public function __set($option, $value)
{
return $this->_options[$option] = $value;
$this->_options[$option] = $value;
}

public function enable()
Expand Down
10 changes: 10 additions & 0 deletions Parser/Token/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
use Kadet\Highlighter\Parser\Validator\Validator;
use Kadet\Highlighter\Utils\Helper;

/**
* Class Token
*
* @package Kadet\Highlighter\Parser\Token
*
* @mixin Rule
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes phpstan understand that __get() (same for set and call) calls are proxied to the Rule class which in turn makes it realize where the fuck a variable in

return $this->getStart() ? $this->getStart()->inject : $this->rule->language;
is coming from

*/
class Token
{
public const NAME = null;
Expand All @@ -37,7 +44,10 @@ class Token
public $pos;
public $name;
public $id;

/** @var Rule */
public $rule;

public $options;

# region >>> cache
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
![Logo](https://keylighter.kadet.net/img/logo.png)

[![Packagist](https://img.shields.io/packagist/v/kadet/keylighter.svg?style=flat-square)](https://packagist.org/packages/kadet/keylighter)
[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/kadet1090/keylighter.svg?style=flat-square)](https://scrutinizer-ci.com/g/kadet1090/KeyLighter/?branch=master)
[![Travis build](https://img.shields.io/travis/kadet1090/KeyLighter.svg?style=flat-square)](https://travis-ci.org/kadet1090/KeyLighter)
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/kadet1090/keylighter.svg?style=flat-square)](https://scrutinizer-ci.com/g/kadet1090/KeyLighter/?branch=master)
[![GitHub Actions](https://github.com/kadet1090/keylighter/actions/workflows/tests.yml/badge.svg?event=push)](https://github.com/kadet1090/KeyLighter/actions?query=branch:master)
[![GitHub Actions](https://github.com/kadet1090/keylighter/actions/workflows/phpstan.yml/badge.svg?event=push)](https://github.com/kadet1090/KeyLighter/actions?query=branch:master)
[![Try it](https://img.shields.io/badge/www-try%20it-FF9700.svg?style=flat-square)](https://keylighter.kadet.net)
Comment on lines +4 to 6
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OCD-driven comment: badges for GitHub actions don't support a "flat" style so we might wanna change the other badges to not be flat anymore, for the sake of consistency.


[![stability: stable](https://img.shields.io/badge/Public%20API-stable-green.svg?style=flat-square)](Docs/2-basic-usage.md)
Expand All @@ -30,7 +29,7 @@ KeyLighter is supposed to do the same thing - for code.
$ composer require kadet/keylighter
```

To use **KeyLighter** you just need PHP 7.1.3 or later, no special extensions
To use **KeyLighter** you just need PHP 7.3 or later, no special extensions
required.

## Global installation
Expand Down Expand Up @@ -213,7 +212,7 @@ without any problem.
Even though it wasn't supposed to be fastest code highlighter in PHP it is still
quite fast, more than 2x faster than [GeSHi](https://geshi.org/).

## Testing ![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/kadet1090/keylighter.svg?style=flat-square)
## Testing
**KeyLighter** uses `phpunit` for testing:
```bash
$ ./vendor/bin/phpunit
Expand Down
2 changes: 1 addition & 1 deletion Utils/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class Console
{
/**
* @var ConsoleHelper
* @var ConsoleHelper|null
*/
private static $_instance;

Expand Down
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* **PHP** now supports features from PHP 8.x

## Changed
* **BC BREAK** KeyLighter requires PHP 7.1.3+ now (instead of PHP 5.5 as previously)
* **BC BREAK** KeyLighter requires PHP 7.3+ now (instead of PHP 5.5 as previously)
* **BC BREAK** `LaTexFormatter` and `CliFormatter` no longer have `$styles` in constructor, now you should set styles v
via option `styles` `['styles' => [...]]`
* renamed `Kadet\Highlighter\Language\Language::getAliases` to `getMetadata` as it now stores not only aliases
Expand Down
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
}
],
"require": {
"php": "^7.1.3 | ^8.0"
"php": "^7.3|^8.0"
},
"require-dev": {
"ext-json": "*",
"easybook/geshi": "v1.0.8.19",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.4",
"squizlabs/php_codesniffer": "^3.5",
"symfony/console": "^4.4",
Expand All @@ -33,6 +34,9 @@
"bin/keylighter"
],
"config": {
"platform": {
"php": "7.3.33"
},
"sort-packages": true
}
}
Loading