Skip to content
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
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.php-cs-fixer.dist.php export-ignore
/phpstan.neon.dist export-ignore
/phpstan-baseline.neon export-ignore
/phpunit.xml.dist export-ignore
78 changes: 78 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: CI

on:
push:
branches: [main]
pull_request:
workflow_dispatch:

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint:
name: Lint (PHP ${{ matrix.php }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
tools: none
- name: Check syntax
run: find src tests examples -name '*.php' -print0 | xargs -0 -n1 php -l

phpstan:
name: PHPStan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
extensions: curl, bcmath
coverage: none
- uses: ramsey/composer-install@v3
- run: vendor/bin/phpstan analyse --no-progress --error-format=github

cs:
name: Coding standard
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
coverage: none
- uses: ramsey/composer-install@v3
- run: vendor/bin/php-cs-fixer fix --dry-run --diff --show-progress=none

phpunit:
name: PHPUnit (PHP ${{ matrix.php }}, ${{ matrix.dependencies }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
dependencies: [lowest, highest]
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: curl, bcmath
coverage: none
ini-values: error_reporting=-1, display_errors=On
- uses: ramsey/composer-install@v3
with:
dependency-versions: ${{ matrix.dependencies }}
- run: vendor/bin/phpunit
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/vendor
composer.lock
/local_tests/*
/local_tests/*
.phpunit.result.cache
.php-cs-fixer.cache
12 changes: 12 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in([__DIR__ . '/src', __DIR__ . '/tests', __DIR__ . '/examples']);

return (new PhpCsFixer\Config())
->setRules([
'@PSR12' => true,
// Constant visibility needs PHP 7.1. Add 'const' back once the minimum PHP is raised to 7.4.
'modifier_keywords' => ['elements' => ['method', 'property']],
])
->setFinder($finder);
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ Entries for 2.2.3 and earlier were reconstructed from the git history in October

- `CHANGELOG.md`, `SECURITY.md` and a full `CONTRIBUTING.md` (branch model, local setup, coding style, tests and release process).
- `.editorconfig` and `.gitattributes`.
- Dev tooling: PHPUnit 9.6, PHPStan (level 6, with a baseline for the existing code) and PHP-CS-Fixer (PSR-12).
- A GitHub Actions CI workflow: `php -l` and PHPUnit on PHP 7.4 to 8.5 with lowest and highest dependencies, plus PHPStan and a coding-standard check.
- Composer scripts: `composer test`, `composer analyse`, `composer cs` and `composer cs:fix`.
- `homepage` and `support` (issues, source, security policy) in `composer.json`.

### Changed

- **The minimum PHP version is now 7.4** (was 7.0).
- The project is now licensed under MIT. 2.2.3 and earlier were released under GPL-3.0.
- `src/` and `examples/` were reformatted to PSR-12. This is whitespace and brace placement only, with no behaviour change.
- Composer dist archives no longer include `tests/`, `examples/`, `docs/` or dotfiles. The examples are still available in the repository.

## [2.2.3] - 2022-06-29
Expand Down
16 changes: 10 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ If a fix applies to both lines, open the pull request against `2.x`. A maintaine

You need:

- PHP 7.0 or newer with the `curl` and `bcmath` extensions. A current PHP 8.x is recommended so you see deprecation notices. 2.3.0 raises the minimum to 7.4.
- PHP 7.4 or newer with the `curl` and `bcmath` extensions. A current PHP 8.x is recommended so you see deprecation notices.
- [Composer](https://getcomposer.org/).
- A [BitGo testnet](https://app.bitgo-test.com/) account and access token, if you want to run requests against the API. Never use production tokens or real funds while developing.

Expand All @@ -50,26 +50,30 @@ cd BitGoSDK-PHP
composer install
```

`composer install` only generates the autoloader for now, because there are no dev dependencies yet.
`composer install` also installs the dev tools: PHPUnit, PHPStan and PHP-CS-Fixer.

## Coding style

- Follow the style of the surrounding code: 4-space indentation, LF line endings, UTF-8 and a final newline. [.editorconfig](.editorconfig) sets these up for most editors.
- New code should follow [PSR-12](https://www.php-fig.org/psr/psr-12/). 2.3.0 adds PHP-CS-Fixer to enforce it. Until then, don't reformat code you aren't otherwise changing, so diffs stay reviewable.
- Code must follow [PSR-12](https://www.php-fig.org/psr/psr-12/). CI enforces it with PHP-CS-Fixer. Run `composer cs:fix` before you push.
- 2.x changes must not break the public API. Don't rename or remove public methods or reorder their parameters. Widening a type (for example `int` to `int|string`) is fine. Breaking changes go to 3.x.
- Code must still run on the minimum PHP version in `composer.json`. Don't use syntax or functions newer than that.
- Give every public method a docblock with a short description, `@param` lines and `@return`, like the existing methods.

## Running tests

There's no automated test suite yet. 2.3.0 adds PHPUnit, PHPStan and CI, and this section will be updated with the `composer test` workflow. Until then:
CI runs these checks on every pull request. PHPUnit and `php -l` run on PHP 7.4 to 8.5, and PHPUnit runs with both the lowest and the highest allowed dependencies.

1. Check every PHP file for syntax errors:
1. Run the same checks locally:

```sh
find src examples -name '*.php' -exec php -l {} \;
composer test
composer analyse
composer cs
```

PHPStan runs at level 6 against a baseline (`phpstan-baseline.neon`) of the errors in the existing code. Don't add new entries to it. When a fix removes an error, regenerate the baseline with `vendor/bin/phpstan analyse --generate-baseline phpstan-baseline.neon`.

2. Exercise your change against BitGo **testnet**. Copy the relevant script from `examples/` into `local_tests/` (which is gitignored), fill in your testnet token and wallet ID there, and run it from the repository root:

```sh
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ BitGoSDK written in PHP. This SDK contains methods for easily interacting with t

## Requirements

- PHP 7.0 or earlier with:
- PHP 7.4 or newer with:
- cURL
- BCMath

Expand Down
39 changes: 38 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"description": "A BitGo SDK written in PHP",
"type": "library",
"keywords": ["bitgo", "sdk", "bitcoin"],
"homepage": "https://github.com/neto737/BitGoSDK-PHP",
"license": "MIT",

"authors": [
Expand All @@ -12,15 +13,51 @@
}
],

"support": {
"issues": "https://github.com/neto737/BitGoSDK-PHP/issues",
"source": "https://github.com/neto737/BitGoSDK-PHP",
"security": "https://github.com/neto737/BitGoSDK-PHP/security/policy"
},

"autoload": {
"psr-4": {
"neto737\\BitGoSDK\\": "src/"
}
},

"autoload-dev": {
"psr-4": {
"neto737\\BitGoSDK\\Tests\\": "tests/"
}
},

"require": {
"php": ">=7.0",
"php": ">=7.4",
"ext-curl": "*",
"ext-bcmath": "*"
},

"require-dev": {
"friendsofphp/php-cs-fixer": "^3.95",
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^9.6.33"
},

"scripts": {
"test": "phpunit",
"analyse": "phpstan analyse",
"cs": "php-cs-fixer fix --dry-run --diff",
"cs:fix": "php-cs-fixer fix"
},

"scripts-descriptions": {
"test": "Run the PHPUnit test suite.",
"analyse": "Run PHPStan static analysis.",
"cs": "Check the coding standard without changing files.",
"cs:fix": "Fix coding standard violations."
},

"config": {
"sort-packages": true
}
}
2 changes: 1 addition & 1 deletion examples/createAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
$bitgo->walletId = 'WALLET_ID_HERE';

$createAddress = $bitgo->createWalletAddress();
var_dump($createAddress);
var_dump($createAddress);
2 changes: 1 addition & 1 deletion examples/generateWallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
$bitgoExpress->accessToken = 'YOUR_API_KEY_HERE';

$generateWallet = $bitgoExpress->generateWallet('LABEL_HERE', 'CREATE_A_NEW_PASSPHRASE_HERE');
var_dump($generateWallet);
var_dump($generateWallet);
2 changes: 1 addition & 1 deletion examples/getWalletByAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
$bitgo = new BitGoSDK('YOUR_API_KEY_HERE', $coin, true);

$getWalletByAddress = $bitgo->getWalletByAddress('WALLET_ADDRESS_HERE');
var_dump($getWalletByAddress);
var_dump($getWalletByAddress);
2 changes: 1 addition & 1 deletion examples/receiveWebhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
//YOU ARE RECEIVING A TRANSACTION...
} else {
//YOU ARE SENDING A TRANSACTION...
}
}
2 changes: 1 addition & 1 deletion examples/sendTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
$amount = BitGoSDK::toSatoshi($value_in_btc);

$sendTransaction = $bitgoExpress->sendTransaction('DESTINATION_ADDRESS', $amount, 'YOUR_WALLET_PASSPHRASE');
var_dump($sendTransaction);
var_dump($sendTransaction);
2 changes: 1 addition & 1 deletion examples/sendTransactionToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/**
* $sendTo array needs to be a multidimensional array
* All amounts in this array needs to be integer (int) values
* If you need convert bitcoin value into satoshi value just use toSatoshi function
* If you need convert bitcoin value into satoshi value just use toSatoshi function
*/
$sendTo = [
[
Expand Down
Loading
Loading