Skip to content

Commit d194357

Browse files
committed
Extending doc blocks and return types
1 parent 0c6cf2a commit d194357

22 files changed

+746
-171
lines changed

.php_cs.dist.php

Lines changed: 0 additions & 37 deletions
This file was deleted.

README.md

Lines changed: 156 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1+
# Laravel Companies House
2+
13
<p align="center">
24

35
![](./companies-house-laravel.png)
46

57
</p>
68

7-
# A Laravel wrapper to get companies house information and validate company numbers
8-
99
[![Latest Version on Packagist](https://img.shields.io/packagist/v/juststeveking/companies-house-laravel.svg?style=flat-square)](https://packagist.org/packages/juststeveking/companies-house-laravel)
1010
![Tests](https://github.com/juststeveking/companies-house-laravel/workflows/Tests/badge.svg?branch=master)
1111
[![Total Downloads](https://img.shields.io/packagist/dt/juststeveking/companies-house-laravel.svg?style=flat-square)](https://packagist.org/packages/juststeveking/companies-house-laravel)
1212

1313

14-
A Laravel wrapper to get companies house information and validate company numbers. This is a work in progress and more methods will be added to the API as they are required.
15-
16-
This has been tested thoroughly in Laravel 8, Laravel 7 is supported but if you find issues please do drop a detailed issue.
14+
A Laravel wrapper to get companies house information and validate company numbers.
1715

1816
## Installation
1917

@@ -25,7 +23,7 @@ composer require juststeveking/companies-house-laravel
2523

2624
You can publish the config file with:
2725
```bash
28-
php artisan vendor:publish --provider="JustSteveKing\CompaniesHouseLaravel\CompaniesHouseLaravelServiceProvider" --tag="config"
26+
php artisan vendor:publish --provider="JustSteveKing\CompaniesHouse\CompaniesHouseServiceProvider" --tag="config"
2927
```
3028

3129
This is the contents of the published config file:
@@ -34,86 +32,194 @@ This is the contents of the published config file:
3432
return [
3533
'api' => [
3634
'key' => env('COMPANIES_HOUSE_KEY', ''),
37-
'url' => env('COMPANIES_HOUSE_URL', 'https://api.companieshouse.gov.uk')
35+
'url' => env('COMPANIES_HOUSE_URL', 'https://api.company-information.service.gov.uk'),
36+
'timeout' => env('COMPANIES_HOUSE_TIMEOUT', 10),
37+
'retry' => [
38+
'times' => env('COMPANIES_HOUSE_RETRY_TIMES', null),
39+
'milliseconds' => env('COMPANIES_HOUSE_RETRY_MILLISECONDS', null),
40+
],
3841
]
3942
];
4043
```
4144

4245
## Usage
4346

44-
Using it inline:
47+
This library is aimed to be easy to use, and slots into Laravel with no issues.
4548

46-
```php
47-
use JustSteveKing\CompaniesHouseLaravel\Client;
49+
The package will install a Service Provider for you, meaning that all you need to do is resolve the `Client` from the container, and start using it.
4850

49-
// Make a new client
50-
$api = Client::make();
5151

52-
// Get Company information from a company number
53-
$company = $api->company('company-number');
54-
```
52+
### Get A Company Profile
5553

56-
Using the validation inline:
54+
To get a company profile, you can quite simply:
5755

5856
```php
59-
$this->validate($request, [
60-
'company_number' => [
61-
'required',
62-
'string',
63-
Rule::companyNumber()
64-
]
65-
]);
57+
use JustSteveKing\CompaniesHouse\Client;
58+
59+
class CompanyController extends Controler
60+
{
61+
public function __construct(
62+
protected Client $service,
63+
) {}
64+
65+
public function __invoke(Request $request)
66+
{
67+
$company = $this->service->company(
68+
companyNumber: $request->get('company_number')
69+
);
70+
}
71+
}
6672
```
6773

68-
Searching for a company by name, please note this will return an empty collection if there are no results:
74+
75+
## Get A Companies Officers
76+
77+
You can get a `Collection` of Company Officers using the companies number:
6978

7079
```php
71-
use JustSteveKing\CompaniesHouseLaravel\Client;
80+
use JustSteveKing\CompaniesHouse\Client;
81+
82+
class CompanyOfficersController extends Controler
83+
{
84+
public function __construct(
85+
protected Client $service,
86+
) {}
87+
88+
public function __invoke(Request $request)
89+
{
90+
$company = $this->service->officers(
91+
companyNumber: $request->get('company_number')
92+
);
93+
}
94+
}
95+
```
96+
7297

73-
$api = Client::make();
98+
### Get a specific Officer from a Company
7499

75-
// Get a collection of Company\SearchResult inside of a CompanyCollection
76-
$results = $api->searchCompany('Name you want to search');
100+
You can get an `Officer` from a company using the company number and their appointment ID:
77101

78-
// You now have access to all standard Laravel collection methods
79-
$results->each(function ($result) {
80-
// Do something with the result here.
81-
});
102+
```php
103+
use JustSteveKing\CompaniesHouse\Client;
104+
105+
class CompanyOfficerController extends Controler
106+
{
107+
public function __construct(
108+
protected Client $service,
109+
) {}
110+
111+
public function __invoke(Request $request)
112+
{
113+
$company = $this->service->officer(
114+
companyNumber: $request->get('company_number'),
115+
appointmentId: $request->get('appointment_id'),
116+
);
117+
}
118+
}
82119
```
83120

84-
Fetching a Collection of Company Officers will return an OfficerCollection:
85121

86-
```php
87-
use JustSteveKing\CompaniesHouseLaravel\Client;
122+
### Searching
123+
124+
There are a few options when it comes to searching, you can search for:
125+
126+
- companies
127+
- officers
128+
- disqualified officers
129+
- search all
130+
88131

89-
$api = Client::make();
132+
#### Searching for Companies
90133

91-
// Get a collection of Company\SearchResult inside of a CompanyCollection
92-
$results = $api->getOfficers('company-number');
134+
This will return a `SearchCollection`
93135

94-
// You now have access to all standard Laravel collection methods
95-
$results->each(function ($result) {
96-
// Do something with the result here.
97-
});
136+
```php
137+
use JustSteveKing\CompaniesHouse\Client;
138+
139+
class CompanySearchController extends Controler
140+
{
141+
public function __construct(
142+
protected Client $service,
143+
) {}
144+
145+
public function __invoke(Request $request)
146+
{
147+
$results = $this->service->searchCompany(
148+
query: $request->get('query'),
149+
perPage: 25, //optional
150+
startIndex: 0, //optional
151+
);
152+
}
153+
}
98154
```
99155

100156

101-
## Testing
157+
#### Searching for Officers
158+
159+
This will return a `SearchCollection`
160+
161+
```php
162+
use JustSteveKing\CompaniesHouse\Client;
163+
164+
class OfficersSearchController extends Controler
165+
{
166+
public function __construct(
167+
protected Client $service,
168+
) {}
169+
170+
public function __invoke(Request $request)
171+
{
172+
$results = $this->service->searchOfficers(
173+
query: $request->get('query'),
174+
perPage: 25, //optional
175+
startIndex: 0, //optional
176+
);
177+
}
178+
}
179+
```
102180

103-
### Using this library in your own tests
104181

105-
There is a relatively simple testing utility on this library, that allows you to fake the underlying Http client:
182+
#### Searching everything
183+
184+
This will return a `SearchCollection`
106185

107186
```php
108-
use Illuminate\Support\Facades\Http
109-
use JustSteveKing\CompaniesHouseLaravel\Client;
187+
use JustSteveKing\CompaniesHouse\Client;
188+
189+
class SearchController extends Controler
190+
{
191+
public function __construct(
192+
protected Client $service,
193+
) {}
194+
195+
public function __invoke(Request $request)
196+
{
197+
$results = $this->service->search(
198+
query: $request->get('query'),
199+
perPage: 25, //optional
200+
startIndex: 0, //optional
201+
);
202+
}
203+
}
204+
```
205+
206+
## Validation
207+
208+
Using the validation inline:
110209

111-
$fakedApi = Client::fake([
112-
'https://api.companieshouse.gov.uk/*',
113-
Http::response([], 200, [])
210+
```php
211+
$this->validate($request, [
212+
'company_number' => [
213+
'required',
214+
'string',
215+
Rule::companyNumber()
216+
]
114217
]);
115218
```
116219

220+
221+
## Testing
222+
117223
To understand how to use this part please follow the Laravel documentation for [Testing the Http Client](https://laravel.com/docs/8.x/http-client#testing)
118224

119225

composer.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@
33
"description": "A Laravel wrapper to get companies house information and validate company numbers",
44
"keywords": [
55
"juststeveking",
6-
"companies-house-laravel"
6+
"companies-house-laravel",
7+
"api",
8+
"validation",
9+
"integration",
10+
"companies house"
711
],
812
"homepage": "https://github.com/juststeveking/companies-house-laravel",
913
"license": "MIT",
1014
"authors": [
1115
{
16+
"role": "Developer",
1217
"name": "Steve McDougall",
1318
"email": "juststevemcd@gmail.com",
14-
"homepage": "https://www.juststeveking.uk/",
15-
"role": "Developer"
19+
"homepage": "https://www.juststeveking.uk/"
1620
}
1721
],
1822
"require": {
@@ -42,10 +46,11 @@
4246
"psalm": "vendor/bin/psalm",
4347
"test": "vendor/bin/phpunit -d memory_limit=512M --testdox",
4448
"test-coverage": "vendor/bin/phpunit --coverage-html coverage -d memory_limit=512M --testdox",
45-
"format": "vendor/bin/php-cs-fixer fix --allow-risky=yes"
49+
"format": "vendor/bin/php-cs-fixer fix src/"
4650
},
4751
"config": {
48-
"sort-packages": true
52+
"sort-packages": true,
53+
"optimize-autoloader": true
4954
},
5055
"extra": {
5156
"laravel": {

src/Actions/Company/CreateCompany.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99

1010
class CreateCompany
1111
{
12+
/**
13+
* Handle the creation of a Company
14+
*
15+
* @param Response $response
16+
*
17+
* @return Company
18+
*/
1219
public function handle(Response $response): Company
1320
{
1421
if (is_null($response->json())) {

src/Actions/Officer/CreateOfficer.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88

99
class CreateOfficer
1010
{
11+
/**
12+
* Handle the creation of an Officer
13+
*
14+
* @param Response $response
15+
*
16+
* @return Officer
17+
*/
1118
public function handle(array $item): Officer
1219
{
1320
return Officer::hydrate(

0 commit comments

Comments
 (0)