Skip to content

Commit

Permalink
some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sadikoff committed Aug 15, 2018
1 parent eb1b91e commit f49bed3
Show file tree
Hide file tree
Showing 50 changed files with 588 additions and 500 deletions.
5 changes: 2 additions & 3 deletions .gitattributes
@@ -1,8 +1,7 @@
Tests/ export-ignore
misc/ export-ignore
tests/ export-ignore
.coveralls.yml export-ignore
.travis.yml export-ignore
phpunit.xml.dist export-ignore
.gitignore export-ignore
.gitattributes export-ignore
.php_cs export-ignore
.php_cs.dist export-ignore
7 changes: 2 additions & 5 deletions .gitignore
@@ -1,7 +1,4 @@
.idea/*
vendor/*
phpunit.xml
composer.lock
composer.phar
.buildpath
.project
.settings
.php_cs.cache
3 changes: 1 addition & 2 deletions .php_cs → .php_cs.dist
Expand Up @@ -9,8 +9,7 @@ $finder = PhpCsFixer\Finder::create()
;

return PhpCsFixer\Config::create()
->finder($finder)
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
->setFinder($finder)
->setRules(array(
'@Symfony' => true,
'@Symfony:risky' => true,
Expand Down
11 changes: 8 additions & 3 deletions composer.json
@@ -1,5 +1,5 @@
{
"name": "sadikoff/device-detector",
"name": "koff/device-detector",
"type": "library",
"description": "The Universal Device Detection library, that parses User Agents and detects devices (desktop, tablet, mobile, tv, cars, console, etc.), clients (browsers, media players, mobile apps, feed readers, libraries, etc), operating systems, devices, brands and models.",
"keywords": ["useragent","parser","devicedetection"],
Expand Down Expand Up @@ -35,12 +35,17 @@
"sort-packages": true
},
"autoload": {
"psr-4": { "DeviceDetector\\": "src/" }
"psr-4": { "Koff\\DeviceDetector\\": "src/" }
},
"autoload-dev": {
"psr-4": { "DeviceDetector\\Tests\\": "tests/" }
"psr-4": { "Koff\\DeviceDetector\\Tests\\": "tests/" }
},
"suggest": {
"doctrine/cache": "Can directly be used for caching purpose"
},
"extra": {
"branch-alias": {
"dev-master": "4.x-dev"
}
}
}
2 changes: 1 addition & 1 deletion src/Cache/DDCacheInterface.php
@@ -1,6 +1,6 @@
<?php

namespace DeviceDetector\Cache;
namespace Koff\DeviceDetector\Cache;

interface DDCacheInterface
{
Expand Down
31 changes: 24 additions & 7 deletions src/Cache/PSR16Bridge.php
@@ -1,12 +1,11 @@
<?php

namespace DeviceDetector\Cache;
namespace Koff\DeviceDetector\Cache;

use Psr\SimpleCache\CacheInterface;

class PSR16Bridge implements DDCacheInterface
{

/**
* @var CacheInterface
*/
Expand All @@ -23,39 +22,57 @@ public function __construct(CacheInterface $cache)
}

/**
* @inheritDoc
* @param $id
*
* @return mixed
*
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public function fetch($id)
{
return $this->cache->get($id, false);
}

/**
* @inheritDoc
* @param $id
*
* @return bool
*
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public function contains($id)
{
return $this->cache->has($id);
}

/**
* @inheritDoc
* @param $id
* @param $data
* @param int $lifeTime
*
* @return bool
*
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public function save($id, $data, $lifeTime = 0)
{
return $this->cache->set($id, $data, func_num_args() < 3 ? null : $lifeTime);
}

/**
* @inheritDoc
* @param $id
*
* @return bool
*
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public function delete($id)
{
return $this->cache->delete($id);
}

/**
* @inheritDoc
* @return bool
*/
public function flushAll()
{
Expand Down
15 changes: 9 additions & 6 deletions src/Cache/PSR6Bridge.php
@@ -1,6 +1,6 @@
<?php

namespace DeviceDetector\Cache;
namespace Koff\DeviceDetector\Cache;

use Psr\Cache\CacheItemPoolInterface;

Expand All @@ -13,6 +13,7 @@ class PSR6Bridge implements DDCacheInterface

/**
* PSR6Bridge constructor.
*
* @param CacheItemPoolInterface $pool
*/
public function __construct(CacheItemPoolInterface $pool)
Expand All @@ -21,24 +22,25 @@ public function __construct(CacheItemPoolInterface $pool)
}

/**
* @inheritDoc
* {@inheritdoc}
*/
public function fetch($id)
{
$item = $this->pool->getItem($id);

return $item->isHit() ? $item->get() : false;
}

/**
* @inheritDoc
* {@inheritdoc}
*/
public function contains($id)
{
return $this->pool->hasItem($id);
}

/**
* @inheritDoc
* {@inheritdoc}
*/
public function save($id, $data, $lifeTime = 0)
{
Expand All @@ -47,19 +49,20 @@ public function save($id, $data, $lifeTime = 0)
if (func_num_args() > 2) {
$item->expiresAfter($lifeTime);
}

return $this->pool->save($item);
}

/**
* @inheritDoc
* {@inheritdoc}
*/
public function delete($id)
{
return $this->pool->deleteItem($id);
}

/**
* @inheritDoc
* {@inheritdoc}
*/
public function flushAll()
{
Expand Down
8 changes: 3 additions & 5 deletions src/Cache/StaticCache.php
@@ -1,19 +1,17 @@
<?php

namespace DeviceDetector\Cache;
namespace Koff\DeviceDetector\Cache;

/**
* Class StaticCache
* Class StaticCache.
*
* Simple Cache that caches in a static property
* (Speeds up multiple detections in one request)
*
* @package DeviceDetector\Cache
*/
class StaticCache implements DDCacheInterface
{
/**
* Holds the static cache data
* Holds the static cache data.
*
* @var array
*/
Expand Down

0 comments on commit f49bed3

Please sign in to comment.