Skip to content

Commit cdc4d45

Browse files
committed
🎉 Init
1 parent cc1f795 commit cdc4d45

12 files changed

+1421
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/vendor/
2+
composer.lock
3+
.php_cs.cache

.php_cs

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php declare(strict_types = 1);
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->in(__DIR__.'/src')
5+
;
6+
7+
return PhpCsFixer\Config::create()
8+
->setRiskyAllowed(true)
9+
->setRules([
10+
'@PSR1' => true,
11+
'@PSR2' => true,
12+
'@Symfony' => true,
13+
'@Symfony:risky' => true,
14+
'@PHP70Migration' => true,
15+
'@PHP70Migration:risky' => true,
16+
'@PHP71Migration' => true,
17+
'phpdoc_summary' => false,
18+
'yoda_style' => false,
19+
'combine_consecutive_unsets' => true,
20+
'blank_line_after_opening_tag' => false,
21+
'phpdoc_to_comment' => false,
22+
'phpdoc_no_empty_return' => false,
23+
'strict_param' => true,
24+
'doctrine_annotation_indentation' => true,
25+
'mb_str_functions' => true,
26+
'native_function_invocation' => true,
27+
'no_short_echo_tag' => true,
28+
'no_unreachable_default_argument_value' => true,
29+
'no_useless_else' => true,
30+
'no_useless_return' => true,
31+
'ordered_class_elements' => true,
32+
'phpdoc_add_missing_param_annotation' => true,
33+
'phpdoc_order' => true,
34+
'simplified_null_return' => false,
35+
'strict_comparison' => true,
36+
'ordered_imports' => ['sortAlgorithm' => 'alpha'],
37+
'declare_equal_normalize' => ['space' => 'single'],
38+
'array_syntax' => ['syntax' => 'short'],
39+
'list_syntax' => ['syntax' => 'short'],
40+
'doctrine_annotation_braces' => ['syntax' => 'with_braces'],
41+
'general_phpdoc_annotation_remove' => ['annotations' => ['author', 'created', 'version', 'package', 'copyright', 'license', 'throws']],
42+
])
43+
->setFinder($finder)
44+
;

.travis.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
language: php
2+
sudo: false
3+
4+
php:
5+
- 7.1
6+
7+
before_script:
8+
- composer self-update
9+
- composer install --dev --prefer-dist --no-interaction -o
10+
11+
script:
12+
- ./vendor/bin/phpcs -p --standard=./ruleset.xml
13+
14+
cache:
15+
directories:
16+
- $COMPOSER_CACHE_DIR
17+
18+
notifications:
19+
email:
20+

README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Symfony Filter Bundle
2+
3+
[![Build Status](https://img.shields.io/travis/rentberry/MapsUtils.svg?style=flat-square)](https://travis-ci.org/rentberry/MapsUtils)
4+
[![License](https://img.shields.io/packagist/l/rentberry/maps-utils.svg?style=flat-square)](https://packagist.org/packages/rentberry/maps-utils)
5+
[![Latest Stable Version](https://img.shields.io/packagist/v/rentberry/maps-utils.svg?style=flat-square)](https://packagist.org/packages/rentberry/maps-utils)
6+
[![Total Downloads](https://img.shields.io/packagist/dt/rentberry/maps-utils.svg?style=flat-square)](https://packagist.org/packages/rentberry/maps-utils)
7+
8+
About
9+
-----
10+
Utils that we use at Rentberry for our search on maps.
11+
12+
Installation
13+
------------
14+
15+
```bash
16+
composer require rentberry/maps-utils
17+
```
18+
19+
20+
Copyright / License
21+
-------------------
22+
23+
See [LICENSE](https://github.com/rentberry/MapsUtils/blob/master/LICENSE)

composer.json

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "rentberry/maps-utils",
3+
"description": "Rentberry maps utils.",
4+
"keywords": ["maps", "utils"],
5+
"homepage": "https://github.com/Rentberry/MapsUtils",
6+
"type": "library",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Denis Golubovskiy",
11+
"email": "[email protected]",
12+
"role": "Creator"
13+
}
14+
],
15+
"support": {
16+
"email": "[email protected]",
17+
"issues": "https://github.com/Rentberry/MapsUtils/issues"
18+
},
19+
"require": {
20+
"php": ">=7.1.0",
21+
"psr/log": "^1.0",
22+
"psr/log-implementation": "^1.0",
23+
"guzzlehttp/guzzle": "^6.3"
24+
},
25+
"require-dev": {
26+
"escapestudios/symfony2-coding-standard": "^3.0",
27+
"slevomat/coding-standard": "^4.0",
28+
"friendsofphp/php-cs-fixer": "^2.3",
29+
"monolog/monolog": "^1.23"
30+
},
31+
"autoload": {
32+
"psr-4": {
33+
"Rentberry\\MapsUtils\\": "src/"
34+
}
35+
}
36+
}

ruleset.xml

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Rentberry">
3+
<description>Rentberry coding standard.</description>
4+
5+
<rule ref="./vendor/escapestudios/symfony2-coding-standard/Symfony"/>
6+
<rule ref="./vendor/slevomat/coding-standard/SlevomatCodingStandard/ruleset.xml" />
7+
8+
<rule ref="./vendor/escapestudios/symfony2-coding-standard/Symfony">
9+
<exclude name="Symfony.Functions.Arguments.Invalid"/>
10+
<exclude name="Symfony.Commenting.License.Warning"/>
11+
<exclude name="Symfony.Commenting.Annotations.Invalid"/>
12+
<exclude name="Symfony.ControlStructure.YodaConditions.Invalid"/>
13+
<exclude name="Symfony.ControlStructure.UnaryOperators.Invalid"/>
14+
<exclude name="Symfony.Functions.ReturnType.Invalid"/>
15+
</rule>
16+
17+
<rule ref="./vendor/slevomat/coding-standard/SlevomatCodingStandard/ruleset.xml">
18+
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.UselessDocComment"/>
19+
<exclude name="SlevomatCodingStandard.ControlStructures.RequireYodaComparison.RequiredYodaComparison"/>
20+
<exclude name="SlevomatCodingStandard.Namespaces.UseOnlyWhitelistedNamespaces"/>
21+
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation.NonFullyQualifiedClassName"/>
22+
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedExceptions"/>
23+
<exclude name="SlevomatCodingStandard.Files.TypeNameMatchesFileName"/>
24+
</rule>
25+
26+
<rule ref="SlevomatCodingStandard.Types.EmptyLinesAroundTypeBraces">
27+
<properties>
28+
<property name="linesCountAfterOpeningBrace" value="0"/>
29+
<property name="linesCountBeforeClosingBrace" value="0"/>
30+
</properties>
31+
</rule>
32+
33+
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
34+
<properties>
35+
<property name="allowFullyQualifiedExceptions" value="true"/>
36+
<property name="allowPartialUses" value="true"/>
37+
<property name="allowFullyQualifiedGlobalClasses" value="true"/>
38+
<property name="allowFullyQualifiedGlobalFunctions" value="true"/>
39+
<property name="allowFullyQualifiedGlobalConstants" value="true"/>
40+
</properties>
41+
</rule>
42+
43+
<rule ref="SlevomatCodingStandard.Commenting.ForbiddenAnnotations">
44+
<properties>
45+
<property name="forbiddenAnnotations" type="array" value="@author, @created, @version, @package, @copyright, @license, @throws"/>
46+
</properties>
47+
</rule>
48+
49+
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
50+
<properties>
51+
<property name="searchAnnotations" value="true"/>
52+
</properties>
53+
</rule>
54+
55+
<rule ref="Squiz.Commenting.FunctionComment.MissingParamComment">
56+
<severity>0</severity>
57+
</rule>
58+
59+
<rule ref="Squiz.Commenting.FunctionComment.InvalidReturn">
60+
<severity>0</severity>
61+
</rule>
62+
63+
<arg name="colors"/>
64+
<arg name="encoding" value="utf-8"/>
65+
<arg name="extensions" value="php"/>
66+
67+
<file>./src</file>
68+
</ruleset>

src/Cache/Cache.php

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Rentberry\MapsUtils\Cache;
4+
5+
/**
6+
* Cache service
7+
*/
8+
class Cache
9+
{
10+
/**
11+
* @var \Memcached
12+
*/
13+
protected $cache;
14+
15+
/**
16+
* @param \Memcached $cache
17+
*/
18+
public function __construct(\Memcached $cache)
19+
{
20+
$this->cache = $cache;
21+
}
22+
23+
/**
24+
* @param CacheInterface $object
25+
*
26+
* @return false|mixed
27+
*/
28+
public function getData(CacheInterface $object)
29+
{
30+
$cacheKey = $object->getCacheKey();
31+
$data = $this->cache->get($cacheKey);
32+
33+
if ($data !== false) {
34+
return $data;
35+
}
36+
37+
$data = $object->getData();
38+
39+
if ($data) {
40+
$this->cache->set($cacheKey, $data);
41+
}
42+
43+
return $data;
44+
}
45+
46+
/**
47+
* Force update data in cache
48+
*
49+
* @param CacheInterface $object
50+
*
51+
* @return false|mixed
52+
*/
53+
public function updateData(CacheInterface $object)
54+
{
55+
$cacheKey = $object->getCacheKey();
56+
$data = $object->getData();
57+
58+
if ($data) {
59+
$this->cache->set($cacheKey, $data);
60+
}
61+
62+
return $data;
63+
}
64+
}

src/Cache/CacheInterface.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Rentberry\MapsUtils\Cache;
4+
5+
/**
6+
* Interface Cache
7+
*/
8+
interface CacheInterface
9+
{
10+
/**
11+
* @return mixed
12+
*/
13+
public function getData();
14+
15+
/**
16+
* @return string
17+
*/
18+
public function getCacheKey(): string;
19+
}

src/Cache/CacheObject.php

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Rentberry\MapsUtils\Cache;
4+
5+
/**
6+
* Cache object
7+
*/
8+
class CacheObject implements CacheInterface
9+
{
10+
/**
11+
* @var string
12+
*/
13+
private $cacheKey;
14+
15+
/**
16+
* @var mixed
17+
*/
18+
private $data;
19+
20+
/**
21+
* @return string
22+
*/
23+
public function getCacheKey(): string
24+
{
25+
return $this->cacheKey;
26+
}
27+
28+
/**
29+
* @return mixed
30+
*/
31+
public function getData()
32+
{
33+
return $this->data;
34+
}
35+
36+
/**
37+
* @param string $cacheKey
38+
*
39+
* @return CacheObject
40+
*/
41+
public function setCacheKey(string $cacheKey): CacheObject
42+
{
43+
$this->cacheKey = $cacheKey;
44+
45+
return $this;
46+
}
47+
48+
/**
49+
* @param mixed $data
50+
*
51+
* @return CacheObject
52+
*/
53+
public function setData($data): CacheObject
54+
{
55+
$this->data = $data;
56+
57+
return $this;
58+
}
59+
}

0 commit comments

Comments
 (0)