src/Repository/RemoteWorkshopRepository.php
/**
     * Load the remote data
     *
     * @throws RequiresNetworkAccessException
     */
Load the remote data
@throws RequiresNetworkAccessException
Load the remote data @throws RequiresNetworkAccessException
private function init(): void
    {
        if ($this->initialised) {
            return;
        }
        if (!checkdnsrr((string) parse_url($this->remoteJsonFile->getPath(), PHP_URL_HOST), 'A')) {
            throw new RequiresNetworkAccessException();
        }
        $requiredKeys = collect(
            ['workshop_code', 'display_name', 'github_owner', 'github_repo_name', 'description', 'type']
        );
        $workshops = $this->remoteJsonFile->read()['workshops'];
        collect($workshops)
            ->filter(function ($workshopData) use ($requiredKeys) {
                    $missingKeyCount = $requiredKeys
                        ->diff(array_map('strval', array_keys($workshopData)))
                        ->count();
                    return $missingKeyCount === 0;
            })
            ->map(function ($workshopData) {
                    return new Workshop(
                        $workshopData['workshop_code'],
                        $workshopData['display_name'],
                        $workshopData['github_owner'],
                        $workshopData['github_repo_name'],
                        $workshopData['description'],
                        $workshopData['type']
                    );
            })
            ->each(function (Workshop $workshop) {
                $this->addWorkshop($workshop);
            });
        $this->initialised = true;
    }
private function init ( ) : void { if ( $ this -> initialised ) { return ; } if ( ! checkdnsrr ( ( string ) parse_url ( $ this -> remoteJsonFile -> getPath ( ) , PHP_URL_HOST ) , 'A' ) ) { throw new RequiresNetworkAccessException ( ) ; } $ requiredKeys = collect ( [ 'workshop_code' , 'display_name' , 'github_owner' , 'github_repo_name' , 'description' , 'type' ] ) ; $ workshops = $ this -> remoteJsonFile -> read ( ) [ 'workshops' ] ; collect ( $ workshops ) -> filter ( function ( $ workshopData ) use ( $ requiredKeys ) { $ missingKeyCount = $ requiredKeys -> diff ( array_map ( 'strval' , array_keys ( $ workshopData ) ) ) -> count ( ) ; return $ missingKeyCount === 0 ; } ) -> map ( function ( $ workshopData ) { return new Workshop ( $ workshopData [ 'workshop_code' ] , $ workshopData [ 'display_name' ] , $ workshopData [ 'github_owner' ] , $ workshopData [ 'github_repo_name' ] , $ workshopData [ 'description' ] , $ workshopData [ 'type' ] ) ; } ) -> each ( function ( Workshop $ workshop ) { $ this -> addWorkshop ( $ workshop ) ; } ) ; $ this -> initialised = true ; }
Load the remote data
 @throws RequiresNetworkAccessException
Load the remote data @throws RequiresNetworkAccessException
/** @var array<array> $workshops */ //true if no missing keys