Skip to content

Commit

Permalink
feat: user model (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkohei authored May 19, 2022
1 parent b0a5dd6 commit 80b1491
Show file tree
Hide file tree
Showing 9 changed files with 622 additions and 155 deletions.
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"require-dev": {
"pestphp/pest": "^1.21",
"phpstan/phpstan": "^1.3"
"phpstan/phpstan": "^1.6"
},
"scripts": {
"tests": [
Expand All @@ -36,5 +36,10 @@
"tests:phpstan": "@php ./vendor/bin/phpstan analyse --ansi --memory-limit 512M",
"tests:lint": "@php ./vendor/bin/php-cs-fixer fix . --using-cache=no",
"tests:pest": "@php ./vendor/bin/pest --stop-on-failure"
},
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true
}
}
}
76 changes: 76 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
parameters:
ignoreErrors:
-
message: "#^Cannot access offset 'personal_data' on array\\|bool\\.$#"
count: 1
path: src/Loghy.php

-
message: "#^Method Loghy\\\\SDK\\\\Loghy\\:\\:getLoghyId\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Loghy.php

-
message: "#^Method Loghy\\\\SDK\\\\Loghy\\:\\:getLoghyId\\(\\) should return array but returns array\\|bool\\.$#"
count: 1
path: src/Loghy.php

-
message: "#^Method Loghy\\\\SDK\\\\Loghy\\:\\:getUserInfo\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Loghy.php

-
message: "#^Method Loghy\\\\SDK\\\\Loghy\\:\\:requestApi\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Loghy.php

-
message: "#^Method Loghy\\\\SDK\\\\Loghy\\:\\:requestApi\\(\\) should return array\\|null but returns mixed\\.$#"
count: 1
path: src/Loghy.php

-
message: "#^Method Loghy\\\\SDK\\\\Loghy\\:\\:verifyResponse\\(\\) has parameter \\$response with no value type specified in iterable type array\\.$#"
count: 1
path: src/Loghy.php

-
message: "#^Method Loghy\\\\SDK\\\\Loghy\\:\\:verifyResponse\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Loghy.php

-
message: "#^Parameter \\#1 \\$response of method Loghy\\\\SDK\\\\Loghy\\:\\:verifyResponse\\(\\) expects array, array\\|null given\\.$#"
count: 3
path: src/Loghy.php

-
message: "#^Parameter \\#1 \\$response of method Loghy\\\\SDK\\\\Loghy\\:\\:verifyResponse\\(\\) expects array, mixed given\\.$#"
count: 1
path: src/Loghy.php

-
message: "#^Class Loghy\\\\SDK\\\\User implements generic interface ArrayAccess but does not specify its types\\: TKey, TValue$#"
count: 1
path: src/User.php

-
message: "#^Method Loghy\\\\SDK\\\\User\\:\\:getRaw\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/User.php

-
message: "#^Method Loghy\\\\SDK\\\\User\\:\\:map\\(\\) has parameter \\$attributes with no value type specified in iterable type array\\.$#"
count: 1
path: src/User.php

-
message: "#^Method Loghy\\\\SDK\\\\User\\:\\:setRaw\\(\\) has parameter \\$user with no value type specified in iterable type array\\.$#"
count: 1
path: src/User.php

-
message: "#^Property Loghy\\\\SDK\\\\User\\:\\:\\$user type has no value type specified in iterable type array\\.$#"
count: 1
path: src/User.php
8 changes: 3 additions & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
includes:
- phpstan-baseline.neon

parameters:
level: max
paths:
- src

ignoreErrors:
- '#Method [a-zA-Z0-9\\_]+::[a-zA-Z0-9\\_]+\(\) return type has no value type specified in iterable type array.#'
- '#Method [a-zA-Z0-9\\_]+::[a-zA-Z0-9\\_]+\(\) should return array<string, array\|bool\|int\|string>\|null but returns mixed.#'
- '#Method [a-zA-Z0-9\\_]+::[a-zA-Z0-9\\_]+\(\) should return array<string, bool\|int\|string>\|null but returns array<string, array\|bool\|int\|string>\|null.#'
60 changes: 14 additions & 46 deletions src/Contract/LoghyInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,65 +10,33 @@
interface LoghyInterface
{
/**
* Get Loghy ID from a authentication code
* Set the authorization code.
*
* @param string $code
* @return array<string,array|bool|int|string>|null
* @return $this
*/
public function getLoghyId(string $code): ?array;
public function setCode(string $code): static;

/**
* Get user information from a Loghy ID
* Get the User instance for the authenticated user.
*
* @param string $loghyId
* @return array<string,array|bool|int|string>|null
* @return \Loghy\SDK\Contract\User
*/
public function getUserInfo(string $loghyId): ?array;
public function user(): User;

/**
* Set user ID by site to a Loghy ID
* Set user ID by site to a Loghy ID.
*
* @param string $loghyId
* @param string $userId
* @return array<string,bool|int|string>|null
* @param string|null $loghyId
* @return bool
*/
public function putUserId(string $loghyId, string $userId): ?array;
public function putUserId(string $userId, string $loghyId = null): bool;

/**
* Delete user ID by site from a Loghy ID
* Delete user (Loghy ID).
*
* @param string $loghyId
* @return array<string,bool|int|string>|null
* @param string|null $loghyId
* @return bool
*/
public function deleteUserId(string $loghyId): ?array;

/**
* Delete user information from a Loghy ID
*
* @param string $loghyId
* @return array<string,bool|int|string>|null
*/
public function deleteUserInfo(string $loghyId): ?array;

/**
* Delete Loghy ID
*
* @param string $loghyId
* @return array<string,bool|int|string>|null
*/
public function deleteLoghyId(string $loghyId): ?array;

/**
* Set Guzzle HTTP client
*
* @param \GuzzleHttp\Client $client
*/
public function setHttpClient(\GuzzleHttp\Client $client): void;

/**
* Get Guzzle HTTP Client
*
* @return \GuzzleHttp\Client
*/
public function httpClient(): \GuzzleHttp\Client;
public function deleteUser(string $loghyId = null): bool;
}
51 changes: 51 additions & 0 deletions src/Contract/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

namespace Loghy\SDK\Contract;

/**
* Interface User
*/
interface User
{
/**
* Get the unique identifier for the user issued by social providers.
*
* @return string
*/
public function getId(): string;

/**
* Get the type of social provider.
*/
public function getType(): string;

/**
* Get the unique identifier for the user issued by Loghy.
*
* @return string
*/
public function getLoghyId(): string;

/**
* Get the identifier the user issued by the sites.
*
* @return string
*/
public function getUserId(): ?string;

/**
* Get the name of the user.
*
* @return string
*/
public function getName(): ?string;

/**
* Get the e-mail address of the user.
*
* @return string
*/
public function getEmail(): ?string;
}
Loading

0 comments on commit 80b1491

Please sign in to comment.