Skip to content

Commit

Permalink
Merge pull request #1 from CubiclDev/update8.2
Browse files Browse the repository at this point in the history
Update dependencies
  • Loading branch information
1blankz7 authored Jun 2, 2023
2 parents 2d46256 + 9697a73 commit bc80395
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 52 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: CI Tests

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
operating-system: [ ubuntu-latest ]
php: [ '8.1', '8.2' ]

name: PHP ${{ matrix.php }}

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v2
coverage: none
ini-values: expose_php=1

- name: Validate composer.json and composer.lock
run: composer validate

- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run tests suite
run: composer tests

- name: Run phpstan
run: composer analyze

- uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
17 changes: 0 additions & 17 deletions .travis.yml

This file was deleted.

5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
Cubicl\Sorting Module
==============

[![Build Status](https://travis-ci.org/CubiclDev/php-sorting.svg?branch=master)](https://travis-ci.org/CubiclDev/php-sorting)
# Cubicl\Sorting Module

Implementation of a generic sorting system with an interface definition compatible
to the [Comparable RFC](https://wiki.php.net/rfc/comparable).
Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
}
],
"scripts": {
"check": ["@analyze", "@test"],
"test": "phpunit tests",
"check": ["@analyze", "@tests"],
"tests": "phpunit tests",
"analyze": "phpstan analyse --level max src"
},
"require-dev": {
"phpunit/phpunit": "^7.5",
"phpstan/phpstan": "^0.11.4"
"phpunit/phpunit": "^9.6.8",
"phpstan/phpstan": "^1.10.15",
"phpspec/prophecy-phpunit": "^2.0.2"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 1 addition & 3 deletions src/Comparable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

/**
* Interface for the natural ordering of objects.
*
* @package Cubicl\Sorting
*/
interface Comparable {

Expand All @@ -22,5 +20,5 @@ interface Comparable {
* @return int
* @throws InvalidComparisonException
*/
public function compareTo($other);
public function compareTo(mixed $other): int;
}
9 changes: 2 additions & 7 deletions src/SortManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@

namespace Cubicl\Sorting;

/**
* Class SortManager
*
* @package Cubicl\Sorting
*/
class SortManager implements SortManagerInterface
{
/**
* @inheritdoc
*/
public function sortWithComparator(ComparatorInterface $comparator, array $list)
public function sortWithComparator(ComparatorInterface $comparator, array $list): array
{
usort($list, [$comparator, 'compare']);

Expand All @@ -22,7 +17,7 @@ public function sortWithComparator(ComparatorInterface $comparator, array $list)
/**
* @inheritdoc
*/
public function sortComparable(array $list)
public function sortComparable(array $list): array
{
usort(
$list,
Expand Down
13 changes: 6 additions & 7 deletions src/SortManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,27 @@
* A sort manager handles user defined sorting of objects or value types. Make sure
* that the objects or the values you want to sort have a total ordering, otherwise
* the result of the methods is not specified.
*
* @package Cubicl\Sorting
*/
interface SortManagerInterface
{
/**
* Sort a list of values or objects by a given comparator.
*
* @phpstan-template T
* @param ComparatorInterface $comparator
* @param array $list a possible unsorted list
* @param array<T> $list a possible unsorted list
*
* @return array the sorted list
* @return array<T> the sorted list
*/
public function sortWithComparator(ComparatorInterface $comparator, array $list);
public function sortWithComparator(ComparatorInterface $comparator, array $list): array;


/**
* Sort the list of objects by their natural order.
*
* @param Comparable[] $list
*
* @return array the sorted list
* @return Comparable[] the sorted list
*/
public function sortComparable(array $list);
public function sortComparable(array $list): array;
}
14 changes: 4 additions & 10 deletions tests/Unit/SortManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,21 @@
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
use Prophecy\PhpUnit\ProphecyTrait;
use Cubicl\Sorting\Comparable;
use Cubicl\Sorting\ComparatorInterface;
use Cubicl\Sorting\SortManager;
use Cubicl\Sorting\SortManagerInterface;

/**
* Class SortManagerTest
*
* @package Cubicl\Sorting
*/
class SortManagerTest extends TestCase
{
/**
* @var SortManagerInterface
*/
private $sortManager;
use ProphecyTrait;
private SortManagerInterface $sortManager;

/**
*
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->sortManager = new SortManager();
Expand Down

0 comments on commit bc80395

Please sign in to comment.