Skip to content

Commit

Permalink
Merge pull request #155 from Orange-Management/develop
Browse files Browse the repository at this point in the history
code style fixes
  • Loading branch information
spl1nes authored Feb 3, 2018
2 parents 02fd061 + 8a42dc0 commit 4bb778f
Show file tree
Hide file tree
Showing 1,320 changed files with 26,149 additions and 13,858 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.log
78 changes: 41 additions & 37 deletions Account/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @package phpOMS\Account
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
* @link http://website.orange-management.de
*/
declare(strict_types=1);
declare(strict_types = 1);

namespace phpOMS\Account;

Expand All @@ -22,14 +21,13 @@

/**
* Account class.
*
* The account class is the base model for accounts. This model contains the most common account
* information. This model is not comparable to a profile which contains much more information.
*
* @category Framework
* The account class is the base model for accounts. This model contains the most common account
* information. This model is not comparable to a profile which contains much more information.
*
* @package phpOMS\Account
* @license OMS License 1.0
* @link http://orange-management.com
* @link http://website.orange-management.de
* @since 1.0.0
*/
class Account implements ArrayableInterface, \JsonSerializable
Expand Down Expand Up @@ -136,15 +134,15 @@ class Account implements ArrayableInterface, \JsonSerializable
/**
* Account type.
*
* @var AccountType|int
* @var int
* @since 1.0.0
*/
protected $type = AccountType::USER;

/**
* Account status.
*
* @var AccountStatus|int
* @var int
* @since 1.0.0
*/
protected $status = AccountStatus::INACTIVE;
Expand All @@ -159,7 +157,7 @@ class Account implements ArrayableInterface, \JsonSerializable

/**
* Constructor.
*
*
* The constructor automatically sets the created date as well as the last activity to now.
*
* @param int $id Account id
Expand All @@ -168,10 +166,10 @@ class Account implements ArrayableInterface, \JsonSerializable
*/
public function __construct(int $id = 0)
{
$this->createdAt = new \DateTime('now');
$this->createdAt = new \DateTime('now');
$this->lastActive = new \DateTime('now');
$this->id = $id;
$this->l11n = new NullLocalization();
$this->id = $id;
$this->l11n = new NullLocalization();
}

/**
Expand All @@ -188,7 +186,7 @@ public function getId() : int

/**
* Get localization.
*
*
* Every account can have a different localization which can be accessed here.
*
* @return Localization
Expand All @@ -202,8 +200,8 @@ public function getL11n() : Localization

/**
* Get groups.
*
* Every account can belong to multiple groups.
*
* Every account can belong to multiple groups.
* These groups usually are used for permissions and categorize accounts.
*
* @return array Returns array of all groups
Expand All @@ -217,9 +215,9 @@ public function getGroups() : array

/**
* Add group.
*
*
* @param mixed $group Group to add
*
*
* @return void
*
* @since 1.0.0
Expand All @@ -245,7 +243,7 @@ public function setL11n(Localization $l11n) /* : void */

/**
* Set permissions.
*
*
* The method accepts an array of permissions. All existing permissions are replaced.
*
* @param PermissionAbstract[] $permissions
Expand All @@ -261,7 +259,7 @@ public function setPermissions(array $permissions) /* : void */

/**
* Add permissions.
*
*
* Adds permissions to the account
*
* @param PermissionAbstract[] $permissions Array of permissions to add to the account
Expand All @@ -277,7 +275,7 @@ public function addPermissions(array $permissions) /* : void */

/**
* Add permission.
*
*
* Adds a single permission to the account
*
* @param PermissionAbstract $permission Permission to add to the account
Expand All @@ -293,7 +291,7 @@ public function addPermission(PermissionAbstract $permission) /* : void */

/**
* Get permissions.
*
*
* @return array
*
* @since 1.0.0
Expand All @@ -307,7 +305,7 @@ public function getPermissions() : array
* Has permissions.
*
* Checks if the account has a permission defined
*
*
* @param int $permission Permission to check
* @param int $unit Unit Unit to check (null if all are acceptable)
* @param string $app App App to check (null if all are acceptable)
Expand All @@ -324,14 +322,15 @@ public function hasPermission(int $permission, int $unit = null, string $app = n
{
$app = isset($app) ? strtolower($app) : $app;

foreach($this->permissions as $p) {
if(($p->getUnit() === $unit || $p->getUnit() === null || !isset($unit))
&& ($p->getApp() === $app || $p->getApp() === null || !isset($app))
&& ($p->getModule() === $module || $p->getModule() === null || !isset($module))
&& ($p->getType() === $type || $p->getType() === null || !isset($type))
&& ($p->getElement() === $element || $p->getElement() === null || !isset($element))
&& ($p->getComponent() === $component || $p->getComponent() === null || !isset($component))
&& ($p->getPermission() | $permission) === $p->getPermission()) {
foreach ($this->permissions as $p) {
if (($p->getUnit() === $unit || $p->getUnit() === null || !isset($unit))
&& ($p->getApp() === $app || $p->getApp() === null || !isset($app))
&& ($p->getModule() === $module || $p->getModule() === null || !isset($module))
&& ($p->getType() === $type || $p->getType() === null || !isset($type))
&& ($p->getElement() === $element || $p->getElement() === null || !isset($element))
&& ($p->getComponent() === $component || $p->getComponent() === null || !isset($component))
&& ($p->getPermission() | $permission) === $p->getPermission()
) {
return true;
}
}
Expand Down Expand Up @@ -447,7 +446,7 @@ public function getEmail() : string
* @param string $email Email
*
* @return void
*
*
* @throws \InvalidArgumentException Exception is thrown if the provided string is not a valid email
*
* @since 1.0.0
Expand Down Expand Up @@ -556,11 +555,17 @@ public function getCreatedAt() : \DateTime
*
* @return void
*
* @throws \Exception
*
* @since 1.0.0
*/
public function generatePassword(string $password) /* : void */
{
$this->password = password_hash($password, PASSWORD_DEFAULT);
$this->password = \password_hash($password, \PASSWORD_DEFAULT);

if ($this->password === false) {
throw new \Exception();
}
}

/**
Expand Down Expand Up @@ -625,13 +630,12 @@ public function toArray() : array
/**
* Json serialize.
*
* @return string
* @return array
*
* @since 1.0.0
*/
public function jsonSerialize()
{
return $this->toArray();
}

}
41 changes: 8 additions & 33 deletions Account/AccountManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,27 @@
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @package phpOMS\Account
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
* @link http://website.orange-management.de
*/
declare(strict_types=1);
declare(strict_types = 1);

namespace phpOMS\Account;

use phpOMS\Auth\Auth;
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
use phpOMS\DataStorage\Session\SessionInterface;

/**
* Account manager class.
*
* The account manager is used to manage multiple accounts.
*
* @category Framework
* The account manager is used to manage multiple accounts.
*
* @package phpOMS\Account
* @license OMS License 1.0
* @link http://orange-management.com
* @link http://website.orange-management.de
* @since 1.0.0
*/
class AccountManager implements \Countable
Expand All @@ -49,14 +46,6 @@ class AccountManager implements \Countable
*/
private $session = null;

/**
* Authenticator.
*
* @var Auth
* @since 1.0.0
*/
private $auth = null;

/**
* Constructor.
*
Expand All @@ -66,8 +55,7 @@ class AccountManager implements \Countable
*/
public function __construct(SessionInterface $session)
{
$this->session = $session;
$this->auth = new Auth($this->session);
$this->session = $session;
}

/**
Expand All @@ -82,7 +70,7 @@ public function __construct(SessionInterface $session)
public function get(int $id = 0) : Account
{
if ($id === 0) {
$account = new Account($this->auth->authenticate());
$account = new Account(Auth::authenticate($this->session));

if (!isset($this->accounts[$account->getId()])) {
$this->accounts[$account->getId()] = $account;
Expand All @@ -94,18 +82,6 @@ public function get(int $id = 0) : Account
return $this->accounts[$id] ?? new NullAccount();
}

/**
* Returns the authentication manager
*
* @return Auth
*
* @since 1.0.0
*/
public function getAuth() : Auth
{
return $this->auth;
}

/**
* Add account.
*
Expand Down Expand Up @@ -157,5 +133,4 @@ public function count() : int
{
return count($this->accounts);
}

}
10 changes: 4 additions & 6 deletions Account/AccountStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @package phpOMS\Account
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
* @link http://website.orange-management.de
*/
declare(strict_types=1);
declare(strict_types = 1);

namespace phpOMS\Account;

Expand All @@ -20,10 +19,9 @@
/**
* Account status enum.
*
* @category Framework
* @package phpOMS\Account
* @license OMS License 1.0
* @link http://orange-management.com
* @link http://website.orange-management.de
* @since 1.0.0
*/
abstract class AccountStatus extends Enum
Expand Down
10 changes: 4 additions & 6 deletions Account/AccountType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @package phpOMS\Account
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
* @link http://website.orange-management.de
*/
declare(strict_types=1);
declare(strict_types = 1);

namespace phpOMS\Account;

Expand All @@ -20,10 +19,9 @@
/**
* Account type enum.
*
* @category Framework
* @package phpOMS\Account
* @license OMS License 1.0
* @link http://orange-management.com
* @link http://website.orange-management.de
* @since 1.0.0
*/
abstract class AccountType extends Enum
Expand Down
Loading

0 comments on commit 4bb778f

Please sign in to comment.