<commit_before>#!/usr/bin/env php
<?php

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../data/ships.php';
$loop   = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($loop);
$conns  = new \SplObjectStorage();

$ip   = array_key_exists(1, $argv) ? $argv[1] : '127.0.0.1';
$port = array_key_exists(2, $argv) ? $argv[2] : 1337;

$dbh        = new \PDO('sqlite:'. __DIR__ . '/../data/games');
$repository = new \Wecamp\FlyingLiqourice\Storage\SqliteGameRepository($dbh);

$socket->on('connection', function ($conn) use ($conns, $repository) {
    $conn->id = '';
    $conns->attach($conn);
    $conn->write(PHP_EOL . PHP_EOL);
    $conn->write(showShip() . PHP_EOL);
    $conn->write('WELCOME TO BATTLESHIP' . PHP_EOL);
    $conn->write(PHP_EOL . PHP_EOL);
    $conn->write('Use `help` to see all available commands' . PHP_EOL);

    $conn->on('data', function ($data) use ($conns, $conn, $repository) {
        foreach ($conns as $current) {
            if ($conn === $current) {
                $service = new \Wecamp\FlyingLiqourice\Service\ServiceListener($data, $conn->id, $repository);
                try {
                    $current->write($service->run() . PHP_EOL);
                    $conn->id = (string) $service->id();
                } catch (\InvalidArgumentException $e) {
                    $current->write('ERROR ' . get_class($e) . PHP_EOL);
                }
            }<commit_msg>codestyle fix<commit_after>#!/usr/bin/env php
<?php

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../data/ships.php';
$loop   = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($loop);
$conns  = new \SplObjectStorage();

$ip   = array_key_exists(1, $argv) ? $argv[1] : '127.0.0.1';
$port = array_key_exists(2, $argv) ? $argv[2] : 1337;

$dbh        = new \PDO('sqlite:' . __DIR__ . '/../data/games');
$repository = new \Wecamp\FlyingLiqourice\Storage\SqliteGameRepository($dbh);

$socket->on('connection', function ($conn) use ($conns, $repository) {
    $conn->id = '';
    $conns->attach($conn);
    $conn->write(PHP_EOL . PHP_EOL);
    $conn->write(showShip() . PHP_EOL);
    $conn->write('WELCOME TO BATTLESHIP' . PHP_EOL);
    $conn->write(PHP_EOL . PHP_EOL);
    $conn->write('Use `help` to see all available commands' . PHP_EOL);

    $conn->on('data', function ($data) use ($conns, $conn, $repository) {
        foreach ($conns as $current) {
            if ($conn === $current) {
                $service = new \Wecamp\FlyingLiqourice\Service\ServiceListener($data, $conn->id, $repository);
                try {
                    $current->write($service->run() . PHP_EOL);
                    $conn->id = (string) $service->id();
                } catch (\InvalidArgumentException $e) {
                    $current->write('ERROR ' . get_class($e) . PHP_EOL);
                }
            }
{'fraction_non_alphanumeric': 0.19120193972982336, 'fraction_numerical': 0.009698649116730169, 'mean_word_length': 2.6145181476846058, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3467900', 'n_tokens_mistral': 1021, 'n_tokens_neox': 983, 'n_words': 185}