PHPackages                             hyraiq/uk-companies-house-lookup - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. hyraiq/uk-companies-house-lookup

ActiveLibrary

hyraiq/uk-companies-house-lookup
================================

UK business number validation and verification using the UK Companies House web services API

2.0.0(11mo ago)3126.5k—0%MITPHPPHP &gt;=8.1CI passing

Since Mar 29Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/hyraiq/uk-companies-house-lookup)[ Packagist](https://packagist.org/packages/hyraiq/uk-companies-house-lookup)[ RSS](/packages/hyraiq-uk-companies-house-lookup/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (20)Versions (7)Used By (0)

hyraiq/uk-companies-house-lookup
================================

[](#hyraiquk-companies-house-lookup)

A PHP SDK to validate UK Company Registration Number (CRNs) and verify them with the [UK Companies House Public Data API](https://developer-specs.company-information.service.gov.uk/companies-house-public-data-api/reference). The difference between validation and verification can be outlined as follows:

- Validation uses a regular expression to check that a given number is a valid CRN. This *does not* contact the API to ensure that the given CRN is assigned to a business
- Verification contacts the Companies House through their API to retrieve information registered against the CRN. It will tell you if the CRN actually belongs to a business.

In order to use the API (only necessary for verification), you'll need to [register an account](https://identity.company-information.service.gov.uk/user/register) to receive an API key.

Type safety
-----------

[](#type-safety)

The SDK utilises the [Symfony Serializer](https://symfony.com/doc/current/components/serializer.html) and the [Symfony Validator](https://symfony.com/doc/current/components/validator.html) to deserialize and validate data returned from the API in order to provide a valid [CompanyResponse](./src/Model/CompanyResponse.php) model. This means that if you receive a response from the SDK, it is guaranteed to be valid.

Invalid responses from the API fall into three categories, which are handled with exceptions:

- `ConnectionException.php`: Unable to connect to the API, or the API returned an unexpected response
- `NumberInvalidException.php`: The CRN is invalid (i.e. validation failed)
- `NumberNotFoundException.php`: The CRN is valid, however it is not assigned to a business (i.e. verification failed)

Usage
-----

[](#usage)

### Installation

[](#installation)

```
$ composer require hyraiq/uk-companies-house-lookup
```

### Configuration with Symfony

[](#configuration-with-symfony)

In `services.yaml`, you need to pass you ABR API key to the `ApiClient` and register the `ApiClient` with the `ApiClientInterface`:

```
Hyra\UkCompaniesHouseLookup\ApiClientInterface: '@Hyra\UkCompaniesHouseLookup\ApiClient'
Hyra\UkCompaniesHouseLookup\ApiClient:
    arguments:
        $apiKey: "%env(UK_COMPANIES_HOUSE_API_KEY)%"
```

You can then inject the `ApiClientInterface` directly into your controllers/services.

```
class VerifyController extends AbtractController
{
    public function __construct(
        private ApiClientInterface $apiClient,
    ) {
    }

    // ...
}
```

### Configuration outside Symfony

[](#configuration-outside-symfony)

If you're not using Symfony, you'll need to instantiate the API client yourself, which can be registered in your service container or just used directly. We have provided some helpers in the `Dependencies` class in order to create the Symfony Serializer and Validator with minimal options.

```
use Hyra\UkCompaniesHouseLookup\Dependencies;
use Hyra\UkCompaniesHouseLookup\ApiClient;

$apiKey = ''

// Whichever http client you choose
$httpClient = new HttpClient();

$denormalizer = Dependencies::serializer();
$validator = Dependencies::validator();

$apiClient = new ApiClient($denormalizer, $validator, $httpClient, $apiKey);
```

### Looking up a business number

[](#looking-up-a-business-number)

Once you have configured your `ApiClient` you can look up an individual CRN. Note, this will validate the CRN before calling the API in order to prevent unnecessary API requests.

```
$number = '04264132';

try {
    $response = $apiClient->lookupNumber($number);
} catch (ConnectionException $e) {
    die($e->getMessage())
} catch (NumberInvalidException) {
    die('Invalid business number');
} catch (NumberNotFoundException) {
    die('Business number not found');
}

echo $response->companyNumber; // 04264132
echo $response->companyName; // BENTLEY CARS LIMITED
echo $response->status; // active
```

Testing
-------

[](#testing)

In automated tests, you can replace the `ApiClient` with the `StubApiClient` in order to mock responses from the API. There is also the `BusinessNumberFaker` which you can use during tests to get both valid and invalid CRNs.

```
use Hyra\UkCompaniesHouseLookup\Stubs\BusinessNumberFaker;
use Hyra\UkCompaniesHouseLookup\Stubs\StubApiClient;

$stubClient = new StubApiClient();

$stubClient->lookupNumber(BusinessNumberFaker::invalidBusinessNumber()); // NumberInvalidException - Note, the stub still uses the validator

$stubClient->lookupNumber(BusinessNumberFaker::validBusinessNumber()); // LogicException - You need to tell the stub how to respond to specific queries

$businessNumber = BusinessNumberFaker::validBusinessNumber();
$stubClient->addNotFoundBusinessNumbers($businessNumber);
$stubClient->lookupNumber($businessNumber); // NumberNotFoundException

$businessNumber = BusinessNumberFaker::validBusinessNumber();
$mockResponse = MockCompanyResponse::valid();
$mockResponse->businessNumber = $businessNumber;

$stubClient->addMockResponse($mockResponse);
$response = $stubClient->lookupNumber($businessNumber); // $response === $mockResponse
```

Contributing
------------

[](#contributing)

All contributions are welcome! You'll need [docker](https://docs.docker.com/engine/install/) installed in order to run tests and CI processes locally. These will also be run against your pull request with any failures added as GitHub annotations in the Files view.

```
# First build the required docker container
$ docker compose build

# Then you can install composer dependencies
$ docker compose run php make vendor

# Now you can run tests and other tools
$ docker compose run php make (fix|psalm|phpstan|phpunit)
```

In order for you PR to be accepted, it will need to be covered by tests and be accepted by:

- [php-cs-fixer](https://github.com/FriendsOfPhp/PHP-CS-Fixer)
- [psalm](https://github.com/vimeo/psalm/)
- [phpstan](https://github.com/phpstan/phpstan)

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance50

Moderate activity, may be stable

Popularity33

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~157 days

Recently: every ~197 days

Total

6

Last Release

358d ago

Major Versions

v1.3.0 → 2.0.02025-05-26

PHP version history (2 changes)v1.0.0PHP &gt;=8.0

v1.3.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/3cfed44ee6ac4e4cec6e652326847c4f71d5acc5bd535c7e6fecde526846a5d9?d=identicon)[procurepro](/maintainers/procurepro)

---

Top Contributors

[![kielabokkie](https://avatars.githubusercontent.com/u/1221750?v=4)](https://github.com/kielabokkie "kielabokkie (8 commits)")[![cborgas](https://avatars.githubusercontent.com/u/27918855?v=4)](https://github.com/cborgas "cborgas (1 commits)")

---

Tags

business-numbercompanies-housesdk-phpuk-business-numberuk-companies-house

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/hyraiq-uk-companies-house-lookup/health.svg)

```
[![Health](https://phpackages.com/badges/hyraiq-uk-companies-house-lookup/health.svg)](https://phpackages.com/packages/hyraiq-uk-companies-house-lookup)
```

###  Alternatives

[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[web-auth/webauthn-framework

FIDO2/Webauthn library for PHP and Symfony Bundle.

50570.7k1](/packages/web-auth-webauthn-framework)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
