Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bessudnov committed May 7, 2024
1 parent 00171e2 commit 4056aeb
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 16 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"ext-json": "*",
"amocrm/oauth2-amocrm": "^2.0",
"guzzlehttp/guzzle": "6.* || 7.*",
"symfony/dotenv": "3.* || 4.* || 5.* || 6.*",
"symfony/dotenv": "3.* || 4.* || 5.* || 6.* || 7.*",
"fig/http-message-util": "1.*",
"ramsey/uuid": "^3 || ^4",
"lcobucci/jwt": "^3.4.6 || ^4.0.4",
Expand Down
4 changes: 2 additions & 2 deletions src/AmoCRM/Client/AmoCRMApiRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class AmoCRMApiRequest
public const CONNECT_TIMEOUT = 5;
public const REQUEST_TIMEOUT = 20;
//TODO Do not forget to change this on each release
public const LIBRARY_VERSION = '1.7.0';
public const LIBRARY_VERSION = '1.8.0';
public const USER_AGENT = 'amoCRM-API-Library/' . self::LIBRARY_VERSION;

public const SUCCESS_STATUSES = [
Expand Down Expand Up @@ -463,7 +463,7 @@ public function delete(

return $this->delete($method, $body, $queryParams, $headers, true);
} catch (AmoCRMApiNoContentException $e) {
return $response = ['result' => true];
return ['result' => true];
}

return $response;
Expand Down
2 changes: 2 additions & 0 deletions src/AmoCRM/Contracts/Support/Arrayable.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace AmoCRM\Contracts\Support;

interface Arrayable
Expand Down
15 changes: 15 additions & 0 deletions src/AmoCRM/Contracts/Support/Jsonable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace AmoCRM\Contracts\Support;

interface Jsonable
{
/**
* Get the instance as a json.
*
* @return string
*/
public function toJson();
}
7 changes: 2 additions & 5 deletions src/AmoCRM/Models/CustomFields/ChainedList.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace AmoCRM\Models\CustomFields;

use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\Jsonable;
use AmoCRM\Contracts\Support\Arrayable;
use AmoCRM\Contracts\Support\Jsonable;

use function json_encode;

Expand Down Expand Up @@ -71,9 +71,6 @@ public function toArray()
];
}

/**
* @inheritDoc
*/
public function toJson($options = 0)
{
return json_encode($this->toArray(), $options);
Expand Down
34 changes: 27 additions & 7 deletions src/AmoCRM/Models/CustomFields/ChainedLists.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace AmoCRM\Models\CustomFields;

use Illuminate\Support\Collection;

use function array_filter;
use function array_values;
use function is_array;
Expand All @@ -14,16 +12,25 @@
* Коллекция моделей вложенных списков
*
* @since Release Spring 2022
* @template ChainedList
*/
final class ChainedLists extends Collection
final class ChainedLists
{
/** @var array<int, ChainedList> */
protected $items = [];

public function addItem(int $catalogId, ChainedList $data): self
{
$this->items[$catalogId] = $data;

return $this;
}

/**
* @param array $items
*
* @return ChainedLists<ChainedList>
* @return ChainedLists
*/
public static function fromArray(array $items): ChainedLists
public static function fromArray(array $items): self
{
$collection = new self();

Expand All @@ -41,9 +48,22 @@ public static function fromArray(array $items): ChainedLists
$parentCatalogId = (int) ($item['parent_catalog_id'] ?? 0) ?: null;
$title = (string) ($item['title'] ?? '');

$collection->put($catalogId, new ChainedList($catalogId, $parentCatalogId, $title));
$collection->addItem($catalogId, new ChainedList($catalogId, $parentCatalogId, $title));
}

return $collection;
}

/**
* @return array
*/
public function toArray(): array
{
$result = [];
foreach ($this->items as $key => $item) {
$result[$key] = $item->toArray();
}

return $result;
}
}
2 changes: 1 addition & 1 deletion src/AmoCRM/Models/NoteModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class NoteModel extends BaseApiModel implements Arrayable, HasIdInterface
protected $id;

/**
* @var string
* @var int
*/
protected $entityId;

Expand Down

0 comments on commit 4056aeb

Please sign in to comment.