Skip to content

Commit e3cbf3b

Browse files
authored
Upgrade to PHP 8.1 (#4)
1 parent 982d6d1 commit e3cbf3b

File tree

16 files changed

+43
-114
lines changed

16 files changed

+43
-114
lines changed

.github/workflows/build.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
uses: "shivammathur/setup-php@v2"
1919
with:
2020
coverage: "pcov"
21-
php-version: "8.0"
21+
php-version: "8.1"
2222
ini-values: memory_limit=-1
2323

2424
- name: "Cache Composer dependencies"
@@ -27,8 +27,8 @@ jobs:
2727
path: |
2828
~/.composer/cache
2929
vendor
30-
key: "php-8.0"
31-
restore-keys: "php-8.0"
30+
key: "php-8.1"
31+
restore-keys: "php-8.1"
3232

3333
- name: "Validate composer"
3434
run: "composer validate"

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7-
## [Unreleased]
7+
## [1.0.0] - 2022-05-22
8+
- Upgrade to PHP 8
9+
- Add php-cs-fixer
10+
- Add phpstan by @akondas in #1
11+
- Configure GitHub Actions by @akondas in #3
812

913
## [0.1.0] - 2018-03-15
1014
### Added
@@ -13,4 +17,3 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1317
- Storing and validate Blockchain
1418
- Proof of Work with difficulty (missing consensus on the difficulty)
1519
- Communicating with other nodes & controlling the node (based on ReactPHP)
16-

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM php:8.1-cli-alpine
2+
RUN apk add --no-cache bash curl git
3+
RUN docker-php-ext-install pcntl
4+
COPY --from=composer:2.1.5 /usr/bin/composer /usr/bin/composer

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
build:
2+
docker build -t php-blockchain .
3+
4+
shell: build
5+
docker run -it --rm --name php-blockchain-dev -v $(PWD):/var/app -w /var/app php-blockchain:latest /bin/bash
6+
7+
.PHONY: build shell

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Blockchain implementation in PHP
22

3-
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.2-8892BF.svg)](https://php.net/)
4-
[![Build Status](https://travis-ci.org/akondas/php-blockchain.svg?branch=master)](https://travis-ci.org/akondas/php-blockchain)
3+
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%208.1-8892BF.svg)](https://php.net/)
4+
[![Build](https://github.com/akondas/php-blockchain/actions/workflows/build.yaml/badge.svg)](https://github.com/akondas/php-blockchain/actions/workflows/build.yaml)
55
[![License](https://poser.pugx.org/akondas/php-blockchain/license.svg)](https://packagist.org/packages/akondas/php-blockchain)
66

77
Clean code approach to blockchain technology. Learn blockchain by reading source code.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111
],
1212
"require": {
13-
"php": "^8.0",
13+
"php": "^8.1",
1414
"react/http": "^0.8.1",
1515
"friendsofphp/php-cs-fixer": "^3.8"
1616
},

composer.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Block.php

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,57 +11,15 @@ final class Block implements JsonSerializable
1111
{
1212
public const HASH_ALGORITHM = 'sha256';
1313

14-
/**
15-
* @var int
16-
*/
17-
private $index;
18-
19-
/**
20-
* @var string
21-
*/
22-
private $hash;
23-
24-
/**
25-
* @var string
26-
*/
27-
private $previousHash;
28-
29-
/**
30-
* @var \DateTimeImmutable
31-
*/
32-
private $createdAt;
33-
34-
/**
35-
* @var string
36-
*/
37-
private $data;
38-
39-
/**
40-
* @var int
41-
*/
42-
private $difficulty;
43-
44-
/**
45-
* @var int
46-
*/
47-
private $nonce;
48-
4914
public function __construct(
50-
int $index,
51-
string $hash,
52-
string $previousHash,
53-
DateTimeImmutable $createdAt,
54-
string $data,
55-
int $difficulty,
56-
int $nonce
15+
private int $index,
16+
private string $hash,
17+
private string $previousHash,
18+
private DateTimeImmutable $createdAt,
19+
private string $data,
20+
private int $difficulty,
21+
private int $nonce
5722
) {
58-
$this->index = $index;
59-
$this->hash = $hash;
60-
$this->previousHash = $previousHash;
61-
$this->createdAt = $createdAt;
62-
$this->data = $data;
63-
$this->difficulty = $difficulty;
64-
$this->nonce = $nonce;
6523
}
6624

6725
public static function genesis(): self
@@ -134,7 +92,7 @@ public static function calculateHash(
13492
}
13593

13694
/**
137-
* @return mixed[]
95+
* @return array<string,string|int>
13896
*/
13997
public function jsonSerialize(): array
14098
{

src/Blockchain.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function withLastBlockOnly(): self
5454
}
5555

5656
/**
57-
* @return Block[]
57+
* @return non-empty-array<Block>
5858
*/
5959
public function blocks(): array
6060
{

src/Miner.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,8 @@
99

1010
final class Miner
1111
{
12-
/**
13-
* @var Blockchain
14-
*/
15-
private $blockchain;
16-
17-
/**
18-
* @var HashDifficulty
19-
*/
20-
private $hashDifficulty;
21-
22-
public function __construct(Blockchain $blockchain, HashDifficulty $hashDifficulty)
12+
public function __construct(private Blockchain $blockchain, private HashDifficulty $hashDifficulty)
2313
{
24-
$this->blockchain = $blockchain;
25-
$this->hashDifficulty = $hashDifficulty;
2614
}
2715

2816
public function mineBlock(string $data): Block

0 commit comments

Comments
 (0)