tegenterter/fide-data

PHP library for processing open data published by FIDE

dev-master 2024-07-03 12:27 UTC

This package is not auto-updated.

Last update: 2025-07-04 14:51:04 UTC


README

Library for processing open data published by FIDE for PHP

Build Status

Features

  • Download all player rating XML files published by FIDE
  • Read and parse player rating XML files

Documentation

Installation

Use Composer to install the library for your project:

composer require tegenterter/fide-data

Basic Usage

<?php

require __DIR__ . '/vendor/autoload.php';

// Download particular rating file from https://ratings.fide.com/download_lists.phtml
$client = new \FideData\Http\RatingXmlDownloader(__DIR__);
$path = $client->download(\FideData\Enum\RatingType::STANDARD, 2020, 12);

// Read and parse the rating file
$rating = new \FideData\PlayerRating($path);

/** @var \FideData\Structure\Player $player */
foreach ($rating->process() as $player) {
    // Get array representation of the player object
    $array = $player->toArray();

    echo json_encode($array, JSON_PRETTY_PRINT) . PHP_EOL;
    /**
    {
        "fideId": 1503014,
        "name": "Carlsen, Magnus",
        "federation": "NOR",
        "birthYear": 1990,
        "sex": "M",
        "title": "GM",
        "standardRating": {
            "type": "standard",
            "rating": 2862,
            "k": 10
        },
        "rapidRating": null,
        "blitzRating": null,
        "active": true
    } 
    */
}

Testing

The library is covered by unit tests using PHPUnit. You can use the following Composer script to run them:

composer run test