Skip to content

Commit

Permalink
styleci
Browse files Browse the repository at this point in the history
  • Loading branch information
recursivetree committed Oct 13, 2023
1 parent 0c8b4c3 commit 4c41e57
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 43 deletions.
22 changes: 21 additions & 1 deletion src/Contracts/HasTypeID.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
<?php

/*
* This file is part of SeAT
*
* Copyright (C) 2015 to present Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

namespace Seat\Services\Contracts;

/**
Expand All @@ -11,4 +31,4 @@ interface HasTypeID
* @return int The eve type id of this object
*/
public function getTypeID(): int;
}
}
27 changes: 24 additions & 3 deletions src/Contracts/IPriceable.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
<?php

/*
* This file is part of SeAT
*
* Copyright (C) 2015 to present Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

namespace Seat\Services\Contracts;

/**
Expand All @@ -15,9 +35,10 @@ interface IPriceable extends HasTypeID
public function getAmount(): int;

/**
* Set the price of this object
* @param float $price
* Set the price of this object.
*
* @param float $price
* @return void
*/
public function setPrice(float $price): void;
}
}
91 changes: 62 additions & 29 deletions src/Helpers/UserAgentBuilder.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
<?php

/*
* This file is part of SeAT
*
* Copyright (C) 2015 to present Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

namespace Seat\Services\Helpers;

use Composer\InstalledVersions;
Expand All @@ -9,7 +29,7 @@

/**
* A helper to build user agents for seat packages
* Structure and terms according to https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent
* Structure and terms according to https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent.
*/
class UserAgentBuilder
{
Expand All @@ -18,8 +38,9 @@ class UserAgentBuilder
protected array $comments = [];

/**
* Set the product part of the user agent
* @param string $product The new product name
* Set the product part of the user agent.
*
* @param string $product The new product name
* @return $this
*/
public function product(string $product): UserAgentBuilder {
Expand All @@ -29,8 +50,9 @@ public function product(string $product): UserAgentBuilder {
}

/**
* Set the version of the product
* @param string $version
* Set the version of the product.
*
* @param string $version
* @return $this
*/
public function version(string $version): UserAgentBuilder {
Expand All @@ -40,8 +62,9 @@ public function version(string $version): UserAgentBuilder {
}

/**
* Configures the product and version of the user agent for a seat plugin
* @param string|AbstractSeatPlugin $plugin A plugin service provider instance or the FCQN of the service provider (e.g. MyServiceProvider::class)
* Configures the product and version of the user agent for a seat plugin.
*
* @param string|AbstractSeatPlugin $plugin A plugin service provider instance or the FCQN of the service provider (e.g. MyServiceProvider::class)
* @return $this
*/
public function seatPlugin(string|AbstractSeatPlugin $plugin): UserAgentBuilder {
Expand All @@ -55,21 +78,23 @@ public function seatPlugin(string|AbstractSeatPlugin $plugin): UserAgentBuilder
}

/**
* Configures the product and version of the user agent for a packagist package
* @param string $vendor The packagist vendor name
* @param string $package The packagist package name
* Configures the product and version of the user agent for a packagist package.
*
* @param string $vendor The packagist vendor name
* @param string $package The packagist package name
* @return $this
*/
public function packagist(string $vendor, string $package): UserAgentBuilder {
$this->product = sprintf('%s:%s',$vendor, $package);
$this->product = sprintf('%s:%s', $vendor, $package);
$this->version = $this->getPackageVersion($vendor, $package);

return $this;
}

/**
* Adds a comment containing the product and version of the user agent for a seat plugin
* @param string|AbstractSeatPlugin $plugin A plugin service provider instance or the FCQN of the service provider (e.g. MyServiceProvider::class)
* Adds a comment containing the product and version of the user agent for a seat plugin.
*
* @param string|AbstractSeatPlugin $plugin A plugin service provider instance or the FCQN of the service provider (e.g. MyServiceProvider::class)
* @return $this
*/
public function commentSeatPlugin(string|AbstractSeatPlugin $plugin): UserAgentBuilder {
Expand All @@ -83,20 +108,22 @@ public function commentSeatPlugin(string|AbstractSeatPlugin $plugin): UserAgentB
}

/**
* Adds a comment containing the product and version of the user agent for a packagist package
* @param string $vendor The packagist vendor name
* @param string $package The packagist package name
* Adds a comment containing the product and version of the user agent for a packagist package.
*
* @param string $vendor The packagist vendor name
* @param string $package The packagist package name
* @return $this
*/
public function commentPackagist(string $vendor, string $package): UserAgentBuilder {
$this->comment(sprintf('%s:%s/%s',$vendor, $package, $this->getPackageVersion($vendor, $package)));
$this->comment(sprintf('%s:%s/%s', $vendor, $package, $this->getPackageVersion($vendor, $package)));

return $this;
}

/**
* Add a comment to the user agent
* @param string $comment the comment
* Add a comment to the user agent.
*
* @param string $comment the comment
* @return $this
*/
public function comment(string $comment): UserAgentBuilder {
Expand All @@ -107,33 +134,39 @@ public function comment(string $comment): UserAgentBuilder {

/**
* Adds a reasonable set of default comments for any seat plugin.
*
* @return $this
*
* @throws SettingException
*/
public function defaultComments(): UserAgentBuilder {
$this->comment(sprintf('(admin contact: %s)', setting('admin_contact', true) ?? 'not specified'));
$this->comment('(https://github.com/eveseat/seat)');
$this->commentPackagist('eveseat','seat');
$this->commentPackagist('eveseat','web');
$this->commentPackagist('eveseat','eveapi');
$this->commentPackagist('eveseat', 'seat');
$this->commentPackagist('eveseat', 'web');
$this->commentPackagist('eveseat', 'eveapi');

return $this;
}

/**
* Assembles the user agent form its product, version, and comments into a string
* Assembles the user agent form its product, version, and comments into a string.
*
* @return string The user agent
*/
public function build(): string {
if($this->product === null || $this->version===null) {
if($this->product === null || $this->version === null) {
throw new \Error('version or product not set.');
}
return sprintf('%s/%s %s', $this->product, $this->version, implode(' ',$this->comments));

return sprintf('%s/%s %s', $this->product, $this->version, implode(' ', $this->comments));
}

/**
* Gets the installed version of a packagist package
* @param string $vendor The packagist vendor name
* @param string $package The packagist package name
* Gets the installed version of a packagist package.
*
* @param string $vendor The packagist vendor name
* @param string $package The packagist package name
* @return string
*/
private function getPackageVersion(string $vendor, string $package): string {
Expand All @@ -143,4 +176,4 @@ private function getPackageVersion(string $vendor, string $package): string {
return 'unknown';
}
}
}
}
29 changes: 24 additions & 5 deletions src/Items/EveType.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
<?php

namespace Seat\Services\Items;
/*
* This file is part of SeAT
*
* Copyright (C) 2015 to present Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

namespace Seat\Services\Items;

use Seat\Services\Contracts\HasTypeID;

/**
* A basic implementation of HasTypeID
* A basic implementation of HasTypeID.
*/
class EveType implements HasTypeID
{
protected int $type_id;

/**
* @param int|HasTypeID $type_id
* @param int|HasTypeID $type_id
*/
public function __construct(int | HasTypeID $type_id)
public function __construct(int|HasTypeID $type_id)
{
if($type_id instanceof HasTypeID){
$type_id = $type_id->getTypeID();
Expand All @@ -31,4 +50,4 @@ public function getTypeID(): int
{
return $this->type_id;
}
}
}
30 changes: 25 additions & 5 deletions src/Items/PriceableEveType.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
<?php

/*
* This file is part of SeAT
*
* Copyright (C) 2015 to present Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

namespace Seat\Services\Items;

use Seat\Services\Contracts\HasTypeID;
use Seat\Services\Contracts\IPriceable;

/**
* A basic implementation od IPriceable
* A basic implementation od IPriceable.
*/
class PriceableEveType extends EveType implements IPriceable
{
protected float $price;
protected float $amount;

/**
* @param int|HasTypeID $type_id The eve type to be appraised
* @param float $amount The amount of this type to be appraised
* @param int|HasTypeID $type_id The eve type to be appraised
* @param float $amount The amount of this type to be appraised
*/
public function __construct(int|HasTypeID $type_id, float $amount)
{
Expand All @@ -41,11 +61,11 @@ public function getPrice(): float
}

/**
* @param float $price The new price of this item stack
* @param float $price The new price of this item stack
* @return void
*/
public function setPrice(float $price): void
{
$this->price = $price;
}
}
}

0 comments on commit 4c41e57

Please sign in to comment.