Skip to content

Commit

Permalink
Totally unecessary changes (#2)
Browse files Browse the repository at this point in the history
* Update PHP versions list for Travis CI
Adding 7.2, 7.3, 7.4
Removing < 7.2
* Upgrade to phpunit 8.5.x
* Allow nightly to fail
* Add php 7.2+ type safety features
* Adding changelog
* strict typesafety
* Obsessing over perfect test coverage
* Update composer.json to require php 7.2+
  • Loading branch information
Gipetto authored May 16, 2020
1 parent 87aafff commit 85218ee
Show file tree
Hide file tree
Showing 26 changed files with 209 additions and 50 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ nbproject
vendor
clover.xml
composer.lock
.phpunit.result.cache
coverage
14 changes: 8 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
language: php
php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4
- nightly
jobs:
fast_finish: true
allow_failures:
- php: nightly
script: "make test"
before_install: "composer install --dev"
before_install: "composer install"
26 changes: 26 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Changelog

See https://github.com/Gipetto/CowSay/releases for release dates.

## 1.1.0
- No new features. This is a mostly useless update of language compatability.
- Deprecate support for PHP < 7.2
- Introduce PHP 7.2 level type safety features
- Won't have the best support until 7.4 is the baseline

## 1.0.4
- Fixed up PSR-4 class loading

## 1.0.3
- General fixes

## 1.0.2
- General fixes

## 1.0.1
- Better docs
- Full semantic version number
- Composer.json file for submission to Packagist.

## 1.0
- Initial release
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ ifeq ($(strip $(COMPOSER)),)
endif

test-install:
$(COMPOSER) install
$(COMPOSER) install --dev

test:
@PATH=vendor/bin:$(PATH) phpunit --coverage-clover clover.xml \
vendor/bin/phpunit -v\
--coverage-clover clover.xml \
--coverage-html coverage \
--colors \
--configuration tests/phpunit.xml;
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ for command line use. You should install the original Cowsay for that.

## Requirements

- PHP 5.4+
- PHP 7.2+

## Install

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
}
],
"require": {
"php": ">=5.4.0"
"php": ">=7.2.0"
},
"require-dev": {
"phpunit/phpunit": "~4.5.0"
"phpunit/phpunit": "~8.5.0"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions docs/Carcasses.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Bear extends \CowSay\Core\Calf {
(___,'.___)
BEAR;
public function buildCarcass() {
protected function buildCarcass(): string {
return $this->carcass;
}
Expand Down Expand Up @@ -106,7 +106,7 @@ BEAR;
return $this;
}
public function buildCarcass() {
protected function buildCarcass(): string {
return sprintf($this->carcass, $this->getEyes());
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/Carcases/Bear.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace CowSay;

Expand Down Expand Up @@ -55,7 +56,7 @@ public function __construct($message = '', $maxLen = self::DEFAULT_MAX_LEN) {
* @param $eyes
* @return $this
*/
public function setEyes($eyes) {
public function setEyes($eyes): self {
if (strlen($eyes) == 1) {
$eyes .= ' ' . $eyes;
}
Expand All @@ -75,7 +76,7 @@ public function setEyes($eyes) {
*
* @return string
*/
public function buildCarcass() {
protected function buildCarcass(): string {
return sprintf($this->carcass, $this->getEyes());
}
}
1 change: 1 addition & 0 deletions src/Carcases/BorgCow.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace CowSay;

Expand Down
3 changes: 2 additions & 1 deletion src/Carcases/Cow.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace CowSay;

Expand Down Expand Up @@ -29,7 +30,7 @@ class Cow extends \CowSay\Core\Calf {
/**
* @return string
*/
public function buildCarcass() {
protected function buildCarcass(): string {
return sprintf($this->carcass, $this->getEyes(), $this->getTongue(), $this->getUdder(), $this->getPoop());
}
}
1 change: 1 addition & 0 deletions src/Carcases/CrazyCow.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace CowSay;

Expand Down
1 change: 1 addition & 0 deletions src/Carcases/GreedyCow.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace CowSay;

Expand Down
1 change: 1 addition & 0 deletions src/Carcases/ParanoidCow.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace CowSay;

Expand Down
3 changes: 2 additions & 1 deletion src/Carcases/Sheep.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace CowSay;

Expand All @@ -23,7 +24,7 @@ class Sheep extends \CowSay\Core\Calf {
/**
* @return string
*/
public function buildCarcass() {
protected function buildCarcass(): string {
return $this->carcass;
}

Expand Down
1 change: 1 addition & 0 deletions src/Carcases/SurprisedCow.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace CowSay;

Expand Down
3 changes: 2 additions & 1 deletion src/Carcases/Tux.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace CowSay;

Expand All @@ -24,7 +25,7 @@ class Tux extends \CowSay\Core\Calf {
/**
* @return string
*/
public function buildCarcass() {
protected function buildCarcass(): string {
return $this->carcass;
}

Expand Down
1 change: 1 addition & 0 deletions src/Carcases/YouthfulCow.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace CowSay;

Expand Down
39 changes: 20 additions & 19 deletions src/Core/Calf.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace CowSay\Core;

Expand Down Expand Up @@ -26,7 +27,7 @@ abstract class Calf {
protected $message;

/**
* @var string max length of output lines
* @var int max length of output lines
*/
protected $maxLen;

Expand All @@ -39,7 +40,7 @@ abstract class Calf {
* @param $message
* @param int $maxLen
*/
public function __construct($message = '', $maxLen = self::DEFAULT_MAX_LEN) {
public function __construct($message = '', int $maxLen = self::DEFAULT_MAX_LEN) {
$this->setMessage($message);
$this->setMaxLen($maxLen);
}
Expand All @@ -49,7 +50,7 @@ public function __construct($message = '', $maxLen = self::DEFAULT_MAX_LEN) {
*
* @return string
*/
public function say() {
public function say(): string {
return $this->formatMessage() . $this->buildCarcass();
}

Expand All @@ -58,30 +59,30 @@ public function say() {
*
* @return string
*/
abstract public function buildCarcass();
abstract protected function buildCarcass(): string;

/**
* @param $maxLen
* @returns $this;
*/
public function setMaxLen($maxLen) {
$this->maxLen = intVal($maxLen);
protected function setMaxLen(int $maxLen) {
$this->maxLen = $maxLen;

return $this;
}

/**
* @return string
* @return int
*/
public function getMaxLen() {
protected function getMaxLen(): int {
return $this->maxLen;
}

/**
* @param $message
* @returns $this
*/
public function setMessage($message) {
public function setMessage(string $message) {
$this->message = $message;

return $this;
Expand All @@ -90,24 +91,24 @@ public function setMessage($message) {
/**
* @return string
*/
public function getMessage() {
public function getMessage(): string {
return $this->message;
}

/**
* @param $strLen
* @return $this
*/
public function setStrLen($strLen) {
protected function setStrLen(int $strLen) {
$this->strLen = intVal($strLen);

return $this;
}

/**
* @return string
* @return int
*/
public function getStrLen() {
protected function getStrLen(): int {
return $this->strLen;
}

Expand All @@ -116,7 +117,7 @@ public function getStrLen() {
* @param $message
* @return array
*/
protected function splitMessage($message) {
protected function splitMessage(string $message): array {
return explode(PHP_EOL, wordwrap($message, $this->maxLen, PHP_EOL));
}

Expand All @@ -125,7 +126,7 @@ protected function splitMessage($message) {
* @param $lines
* @return $this
*/
protected function calcLineLength($lines) {
protected function calcLineLength(array $lines) {
$strLen = 0;

foreach ($lines as $line) {
Expand All @@ -139,15 +140,15 @@ protected function calcLineLength($lines) {
* Make a border string based on the computer CowSay::$strLen
* @return string
*/
protected function mkBorder() {
protected function mkBorder(): string {
return ' ' . str_repeat('-', $this->getStrLen());
}

/**
* Format the message for output
* @return string
*/
protected function formatMessage() {
protected function formatMessage(): string {
$output = [];

$lines = $this->splitMessage($this->getMessage());
Expand Down Expand Up @@ -186,15 +187,15 @@ protected function formatMessage() {
/**
* @return string
*/
public function __toString() {
public function __toString():string {
return $this->say();
}

/**
* Return a list of traits supported by the carcass
* @return array
*/
public function getSupportedTraits() {
public function getSupportedTraits(): array {
$traits = class_uses(get_called_class());

$parents = class_parents($this);
Expand Down
8 changes: 6 additions & 2 deletions src/Traits/Eyes.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace CowSay\Traits;

Expand All @@ -15,7 +16,7 @@ trait Eyes {
* @param $eyes
* @return $this
*/
public function setEyes($eyes) {
public function setEyes(string $eyes) {
if (strlen($eyes) == 1) {
$eyes .= $eyes;
}
Expand All @@ -28,7 +29,10 @@ public function setEyes($eyes) {
return $this;
}

public function getEyes() {
/**
* @return string
*/
public function getEyes(): string {
return $this->eyes;
}
}
Loading

0 comments on commit 85218ee

Please sign in to comment.