Skip to content

Commit d083a46

Browse files
committed
## v2.6.0:
- Add helper `Bit` - change the `readme.md` - add namespaces to tests
1 parent 39265a6 commit d083a46

26 files changed

+367
-22
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog][keepachangelog] and this project adheres to [Semantic Versioning][semver].
66

7+
## v2.6.0
8+
9+
### Added
10+
11+
- Helper `Bit`: contains operations with bits and bit-masks
12+
713
## v2.5.0
814

915
### Changed
1016

11-
- Logic has been changed for the trait `ConfigurableTrait::configurable`:
17+
- Logic has been changed for the trait `ConfigurableTrait::configurable`:
1218
at first, on applying props, checking a magic method and then a property
1319

14-
1520
## v2.4.2
1621

1722
### Changed

readme.md

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,85 @@
1010
[![codecov](https://codecov.io/gh/efureev/php-support/branch/v2/graph/badge.svg)](https://codecov.io/gh/efureev/php-support/tree/v2)
1111

1212
## Install
13+
1314
```bash
14-
composer require efureev/support "^2.5"
15+
composer require efureev/support "^2.6"
1516
```
1617

18+
## Content
19+
20+
- Helpers
21+
+ Array
22+
- get
23+
- set
24+
- exists
25+
- has
26+
- remove
27+
- removeByValue
28+
- toArray
29+
- dataToArray
30+
- merge
31+
- fromPostgresArray
32+
- toPostgresArray
33+
- toIndexedArray
34+
- accessible
35+
- replaceByTemplate
36+
+ String
37+
- toSnake
38+
- toDelimited
39+
- toScreamingDelimited
40+
- toScreamingSnake
41+
- toKebab
42+
- toCamel
43+
- toLowerCamel
44+
- removeMultiSpace
45+
- replaceStrTo
46+
- replaceByTemplate
47+
+ Json
48+
- htmlEncode
49+
- encode
50+
- decode
51+
+ Bit
52+
- removeFlag
53+
- addFlag
54+
- checkFlag
55+
- exist
56+
- grant
57+
- Global functions
58+
+ value
59+
+ classNamespace
60+
- Exceptions
61+
+ ConfigException
62+
+ Exception
63+
+ InvalidArgumentException
64+
+ InvalidCallException
65+
+ InvalidConfigException
66+
+ InvalidParamException
67+
+ InvalidValueException
68+
+ JsonException
69+
+ MethodNotAllowedException
70+
+ MissingClassException
71+
+ MissingConfigException
72+
+ MissingPropertyException
73+
+ NotSupportedException
74+
+ UnknownMethodException
75+
+ UnknownPropertyException
76+
- Interfaces
77+
+ Arrayable
78+
+ Jsonable
79+
+ Prototype
80+
+ Command
81+
- Traits
82+
+ Maker
83+
+ Metable
84+
+ ConfigurableTrait
85+
+ ArrayStorage
86+
+ ArrayStorageConfigurableTrait
87+
+ Singleton
88+
+ ConsolePrint
89+
1790
## Test
91+
1892
```bash
1993
composer test
2094
composer test-cover # with coverage

src/Helpers/Bit.php

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Php\Support\Helpers;
6+
7+
/**
8+
* Class Bit
9+
*
10+
* @package Php\Support\Helpers
11+
*
12+
*
13+
* Working with bits and bitmasks.
14+
*/
15+
class Bit
16+
{
17+
/**
18+
* Remove bit from $value
19+
*
20+
* @param int $value
21+
* @param int $bit
22+
*
23+
* @return int
24+
*/
25+
public static function removeFlag(int $value, int $bit): int
26+
{
27+
$value &= ~$bit;
28+
29+
return $value;
30+
}
31+
32+
/**
33+
* Set bit to $value
34+
*
35+
* @param int $value
36+
* @param int $bit
37+
*
38+
* @return int
39+
*/
40+
public static function addFlag(int $value, int $bit): int
41+
{
42+
$value |= $bit;
43+
44+
return $value;
45+
}
46+
47+
/**
48+
* Check bit into $value
49+
*
50+
* @param int $value
51+
* @param int $bit
52+
*
53+
* @return bool
54+
*/
55+
public static function checkFlag(int $value, int $bit): bool
56+
{
57+
return ($value & $bit) > 0;
58+
}
59+
60+
61+
/**
62+
* Check a bit is existing in flag`s list
63+
*
64+
* @param array $list
65+
* @param int $bit
66+
*
67+
* @return bool
68+
*/
69+
public static function exist(array $list, int $bit): bool
70+
{
71+
return self::checkFlag(self::grant($list), $bit);
72+
}
73+
74+
/**
75+
* Return value of sum of all bits in list
76+
*
77+
* @param array $list
78+
*
79+
* @return int
80+
*/
81+
public static function grant(array $list): int
82+
{
83+
return array_reduce(
84+
$list,
85+
static function ($prev, $next) {
86+
return $prev | $next;
87+
},
88+
0
89+
);
90+
}
91+
}

tests/Global/BaseTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
declare(strict_types=1);
44

5+
namespace Php\Support\Tests;
6+
57
use PHPUnit\Framework\TestCase;
68

79
/**
@@ -32,8 +34,7 @@ private static function values(): array
3234
'float' => 12.31,
3335
'empty' => '',
3436
'emptyArray' => [],
35-
'cls' => new class
36-
{
37+
'cls' => new class {
3738
function __invoke()
3839
{
3940
return 'cls.test';
@@ -47,7 +48,6 @@ function __invoke()
4748

4849
public function testValue(): void
4950
{
50-
5151
foreach (static::values() as $key => $val) {
5252
$result = value($val);
5353

tests/Interfaces/ArrayableTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
declare(strict_types=1);
44

5+
namespace Php\Support\Tests;
6+
57
use PHPUnit\Framework\TestCase;
68

79
/**

tests/Interfaces/JsonableTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
declare(strict_types=1);
44

5+
namespace Php\Support\Tests;
6+
57
use PHPUnit\Framework\TestCase;
68

79
/**

tests/exceptions/ExceptionTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
declare(strict_types=1);
44

5+
namespace Php\Support\Tests;
6+
57
use Php\Support\Exceptions\Exception;
68
use PHPUnit\Framework\TestCase;
79

tests/exceptions/InvalidArgumentTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
declare(strict_types=1);
44

5+
namespace Php\Support\Tests;
6+
57
use Php\Support\Exceptions\InvalidArgumentException;
68
use PHPUnit\Framework\TestCase;
79

tests/exceptions/InvalidParamTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
declare(strict_types=1);
44

5+
namespace Php\Support\Tests;
6+
57
use Php\Support\Exceptions\InvalidParamException;
68
use PHPUnit\Framework\TestCase;
79

tests/exceptions/JsonExceptionTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
declare(strict_types=1);
44

5+
namespace Php\Support\Tests;
6+
57
use Php\Support\Exceptions\JsonException;
68
use PHPUnit\Framework\TestCase;
79

0 commit comments

Comments
 (0)