Best Cucumber Common Library code snippet using Hook.fromArray
Project.php
Source:Project.php
...98 * @param array $data99 *100 * @return Project101 */102 public static function fromArray(Client $client, array $data)103 {104 $project = new self($data['id']);105 $project->setClient($client);106 if (isset($data['owner'])) {107 $data['owner'] = User::fromArray($client, $data['owner']);108 }109 if (isset($data['namespace']) && \is_array($data['namespace'])) {110 $data['namespace'] = ProjectNamespace::fromArray($client, $data['namespace']);111 }112 if (isset($data['shared_with_groups'])) {113 $groups = [];114 foreach ($data['shared_with_groups'] as $group) {115 foreach ($group as $keys => $value) {116 $group[\str_replace('group_', '', $keys)] = $value;117 unset($group[$keys]);118 }119 $groups[] = Group::fromArray($client, $group);120 }121 $data['shared_with_groups'] = $groups;122 }123 return $project->hydrate($data);124 }125 /**126 * @param Client $client127 * @param string $name128 * @param array $params129 *130 * @return Project131 */132 public static function create(Client $client, string $name, array $params = [])133 {134 $data = $client->projects()->create($name, $params);135 return self::fromArray($client, $data);136 }137 /**138 * @param int $user_id139 * @param Client $client140 * @param string $name141 * @param array $params142 *143 * @return Project144 */145 public static function createForUser(int $user_id, Client $client, string $name, array $params = [])146 {147 $data = $client->projects()->createForUser($user_id, $name, $params);148 return self::fromArray($client, $data);149 }150 /**151 * @param int|string|null $id152 * @param Client|null $client153 *154 * @return void155 */156 public function __construct($id = null, Client $client = null)157 {158 $this->setClient($client);159 $this->setData('id', $id);160 }161 /**162 * @return Project163 */164 public function show()165 {166 $data = $this->client->projects()->show($this->id);167 return self::fromArray($this->getClient(), $data);168 }169 /**170 * @param array $params171 *172 * @return Project173 */174 public function update(array $params)175 {176 $data = $this->client->projects()->update($this->id, $params);177 return self::fromArray($this->getClient(), $data);178 }179 /**180 * @return Project181 */182 public function archive()183 {184 $data = $this->client->projects()->archive($this->id);185 return self::fromArray($this->getClient(), $data);186 }187 /**188 * @return Project189 */190 public function unarchive()191 {192 $data = $this->client->projects()->unarchive($this->id);193 return self::fromArray($this->getClient(), $data);194 }195 /**196 * @return bool197 */198 public function remove()199 {200 $this->client->projects()->remove($this->id);201 return true;202 }203 /**204 * @param string|null $query205 *206 * @return User[]207 */208 public function members(?string $query = null)209 {210 $data = $this->client->projects()->members($this->id, null === $query ? [] : ['query' => $query]);211 $members = [];212 foreach ($data as $member) {213 $members[] = User::fromArray($this->getClient(), $member);214 }215 return $members;216 }217 /**218 * @param int $user_id219 *220 * @return User221 */222 public function member(int $user_id)223 {224 $data = $this->client->projects()->member($this->id, $user_id);225 return User::fromArray($this->getClient(), $data);226 }227 /**228 * @param int $user_id229 * @param int $access_level230 *231 * @return User232 */233 public function addMember(int $user_id, int $access_level)234 {235 $data = $this->client->projects()->addMember($this->id, $user_id, $access_level);236 return User::fromArray($this->getClient(), $data);237 }238 /**239 * @param int $user_id240 * @param int $access_level241 *242 * @return User243 */244 public function saveMember(int $user_id, int $access_level)245 {246 $data = $this->client->projects()->saveMember($this->id, $user_id, $access_level);247 return User::fromArray($this->getClient(), $data);248 }249 /**250 * @param int $user_id251 *252 * @return bool253 */254 public function removeMember(int $user_id)255 {256 $this->client->projects()->removeMember($this->id, $user_id);257 return true;258 }259 /**260 * @param array $parameters261 *262 * @return ProjectHook[]263 *264 * @see Projects::hooks() for available parameters.265 */266 public function hooks(array $parameters = [])267 {268 $data = $this->client->projects()->hooks($this->id, $parameters);269 $hooks = [];270 foreach ($data as $hook) {271 $hooks[] = ProjectHook::fromArray($this->getClient(), $this, $hook);272 }273 return $hooks;274 }275 /**276 * @param int $id277 *278 * @return ProjectHook279 */280 public function hook(int $id)281 {282 $hook = new ProjectHook($this, $id, $this->getClient());283 return $hook->show();284 }285 /**286 * @param string $url287 * @param array $events288 *289 * @return ProjectHook290 */291 public function addHook(string $url, array $events = [])292 {293 $data = $this->client->projects()->addHook($this->id, $url, $events);294 return ProjectHook::fromArray($this->getClient(), $this, $data);295 }296 /**297 * @param int $hook_id298 * @param array $params299 *300 * @return ProjectHook301 */302 public function updateHook(int $hook_id, array $params)303 {304 $hook = new ProjectHook($this, $hook_id, $this->getClient());305 return $hook->update($params);306 }307 /**308 * @param int $hook_id309 *310 * @return bool311 */312 public function removeHook(int $hook_id)313 {314 $hook = new ProjectHook($this, $hook_id, $this->getClient());315 return $hook->delete();316 }317 /**318 * @return Key[]319 */320 public function deployKeys()321 {322 $data = $this->client->projects()->deployKeys($this->id);323 $keys = [];324 foreach ($data as $key) {325 $keys[] = Key::fromArray($this->getClient(), $key);326 }327 return $keys;328 }329 /**330 * @param int $key_id331 *332 * @return Key333 */334 public function deployKey(int $key_id)335 {336 $data = $this->client->projects()->deployKey($this->id, $key_id);337 return Key::fromArray($this->getClient(), $data);338 }339 /**340 * @param string $title341 * @param string $key342 * @param bool $canPush343 *344 * @return Key345 */346 public function addDeployKey(string $title, string $key, bool $canPush = false)347 {348 $data = $this->client->projects()->addDeployKey($this->id, $title, $key, $canPush);349 return Key::fromArray($this->getClient(), $data);350 }351 /**352 * @param int $key_id353 *354 * @return bool355 */356 public function deleteDeployKey(int $key_id)357 {358 $this->client->projects()->deleteDeployKey($this->id, $key_id);359 return true;360 }361 /**362 * @param int $key_id363 *364 * @return bool365 */366 public function enableDeployKey(int $key_id)367 {368 $this->client->projects()->enableDeployKey($this->id, $key_id);369 return true;370 }371 /**372 * @param string $name373 * @param string $ref374 *375 * @return Branch376 */377 public function createBranch(string $name, string $ref)378 {379 $data = $this->client->repositories()->createBranch($this->id, $name, $ref);380 return Branch::fromArray($this->getClient(), $this, $data);381 }382 /**383 * @param string $name384 *385 * @return bool386 */387 public function deleteBranch(string $name)388 {389 $this->client->repositories()->deleteBranch($this->id, $name);390 return true;391 }392 /**393 * @return Branch[]394 */395 public function branches()396 {397 $data = $this->client->repositories()->branches($this->id);398 $branches = [];399 foreach ($data as $branch) {400 $branches[] = Branch::fromArray($this->getClient(), $this, $branch);401 }402 return $branches;403 }404 /**405 * @param string $branch_name406 *407 * @return Branch408 */409 public function branch(string $branch_name)410 {411 $branch = new Branch($this, $branch_name);412 $branch->setClient($this->getClient());413 return $branch->show();414 }415 /**416 * @param string $branch_name417 * @param bool $devPush418 * @param bool $devMerge419 *420 * @return Branch421 */422 public function protectBranch(string $branch_name, bool $devPush = false, bool $devMerge = false)423 {424 $branch = new Branch($this, $branch_name);425 $branch->setClient($this->getClient());426 return $branch->protect($devPush, $devMerge);427 }428 /**429 * @param string $branch_name430 *431 * @return Branch432 */433 public function unprotectBranch(string $branch_name)434 {435 $branch = new Branch($this, $branch_name);436 $branch->setClient($this->getClient());437 return $branch->unprotect();438 }439 /**440 * @return Tag[]441 */442 public function tags()443 {444 $data = $this->client->repositories()->tags($this->id);445 $tags = [];446 foreach ($data as $tag) {447 $tags[] = Tag::fromArray($this->getClient(), $this, $tag);448 }449 return $tags;450 }451 /**452 * @param array $parameters453 *454 * @return Commit[]455 *456 * @see Repositories::commits() for available parameters.457 */458 public function commits(array $parameters = [])459 {460 $data = $this->client->repositories()->commits($this->id, $parameters);461 $commits = [];462 foreach ($data as $commit) {463 $commits[] = Commit::fromArray($this->getClient(), $this, $commit);464 }465 return $commits;466 }467 /**468 * @param string $sha469 *470 * @return Commit471 */472 public function commit(string $sha)473 {474 $data = $this->client->repositories()->commit($this->id, $sha);475 return Commit::fromArray($this->getClient(), $this, $data);476 }477 /**478 * @param string $ref479 * @param array $parameters480 *481 * @return CommitNote[]482 *483 * @see Repositories::commitComments() for available parameters.484 */485 public function commitComments(string $ref, array $parameters = [])486 {487 $data = $this->client->repositories()->commitComments($this->id, $ref, $parameters);488 $comments = [];489 foreach ($data as $comment) {490 $comments[] = CommitNote::fromArray($this->getClient(), $comment);491 }492 return $comments;493 }494 /**495 * @param string $ref496 * @param string $note497 * @param array $params498 *499 * @return CommitNote500 */501 public function createCommitComment(string $ref, string $note, array $params = [])502 {503 $data = $this->client->repositories()->createCommitComment($this->id, $ref, $note, $params);504 return CommitNote::fromArray($this->getClient(), $data);505 }506 /**507 * @param string $sha508 *509 * @return string510 */511 public function diff(string $sha)512 {513 return $this->client->repositories()->diff($this->id, $sha);514 }515 /**516 * @param string $from517 * @param string $to518 *519 * @return Comparison520 */521 public function compare(string $from, string $to)522 {523 $data = $this->client->repositories()->compare($this->id, $from, $to);524 return Comparison::fromArray($this->getClient(), $this, $data);525 }526 /**527 * @param array $params528 *529 * @return Node[]530 */531 public function tree(array $params = [])532 {533 $data = $this->client->repositories()->tree($this->id, $params);534 $tree = [];535 foreach ($data as $node) {536 $tree[] = Node::fromArray($this->getClient(), $this, $node);537 }538 return $tree;539 }540 /**541 * @param string $sha542 * @param string $filepath543 *544 * @return string545 */546 public function getRawFile(string $sha, string $filepath)547 {548 return $this->client->repositoryFiles()->getRawFile($this->id, $sha, $filepath);549 }550 /**551 * @param string $sha552 * @param string $filepath553 *554 * @return array555 */556 public function getFile(string $sha, string $filepath)557 {558 return $this->client->repositoryFiles()->getFile($this->id, $filepath, $sha);559 }560 /**561 * @param string $file_path562 * @param string $content563 * @param string $branch_name564 * @param string $commit_message565 * @param string|null $author_email566 * @param string|null $author_name567 *568 * @return File569 */570 public function createFile(571 string $file_path,572 string $content,573 string $branch_name,574 string $commit_message,575 ?string $author_email = null,576 ?string $author_name = null577 ) {578 $parameters = [579 'file_path' => $file_path,580 'branch' => $branch_name,581 'content' => $content,582 'commit_message' => $commit_message,583 ];584 if (null !== $author_email) {585 $parameters['author_email'] = $author_email;586 }587 if (null !== $author_name) {588 $parameters['author_name'] = $author_name;589 }590 $data = $this->client->repositoryFiles()->createFile($this->id, $parameters);591 return File::fromArray($this->getClient(), $this, $data);592 }593 /**594 * @param string $file_path595 * @param string $content596 * @param string $branch_name597 * @param string $commit_message598 * @param string|null $author_email599 * @param string|null $author_name600 *601 * @return File602 */603 public function updateFile(604 string $file_path,605 string $content,606 string $branch_name,607 string $commit_message,608 ?string $author_email = null,609 ?string $author_name = null610 ) {611 $parameters = [612 'file_path' => $file_path,613 'branch' => $branch_name,614 'content' => $content,615 'commit_message' => $commit_message,616 ];617 if (null !== $author_email) {618 $parameters['author_email'] = $author_email;619 }620 if (null !== $author_name) {621 $parameters['author_name'] = $author_name;622 }623 $data = $this->client->repositoryFiles()->updateFile($this->id, $parameters);624 return File::fromArray($this->getClient(), $this, $data);625 }626 /**627 * @param string $file_path628 * @param string $branch_name629 * @param string $commit_message630 * @param string|null $author_email631 * @param string|null $author_name632 *633 * @return bool634 */635 public function deleteFile(string $file_path, string $branch_name, string $commit_message, ?string $author_email = null, ?string $author_name = null)636 {637 $parameters = [638 'file_path' => $file_path,639 'branch' => $branch_name,640 'commit_message' => $commit_message,641 ];642 if (null !== $author_email) {643 $parameters['author_email'] = $author_email;644 }645 if (null !== $author_name) {646 $parameters['author_name'] = $author_name;647 }648 $this->client->repositoryFiles()->deleteFile($this->id, $parameters);649 return true;650 }651 /**652 * @param array $parameters653 *654 * @return Event[]655 *656 * @see Projects::events() for available parameters.657 */658 public function events(array $parameters = [])659 {660 $data = $this->client->projects()->events($this->id, $parameters);661 $events = [];662 foreach ($data as $event) {663 $events[] = Event::fromArray($this->getClient(), $this, $event);664 }665 return $events;666 }667 /**668 * @param array $parameters669 *670 * @return MergeRequest[]671 *672 * @see MergeRequests::all() for available parameters.673 */674 public function mergeRequests(array $parameters = [])675 {676 $data = $this->client->mergeRequests()->all($this->id, $parameters);677 $mrs = [];678 foreach ($data as $mr) {679 $mrs[] = MergeRequest::fromArray($this->getClient(), $this, $mr);680 }681 return $mrs;682 }683 /**684 * @param int $id685 *686 * @return MergeRequest687 */688 public function mergeRequest(int $id)689 {690 $mr = new MergeRequest($this, $id, $this->getClient());691 return $mr->show();692 }693 /**694 * @param string $source695 * @param string $target696 * @param string $title697 * @param array $parameters {698 *699 * @var int $assignee700 * @var string $description701 * }702 *703 * @return MergeRequest704 */705 public function createMergeRequest(string $source, string $target, string $title, array $parameters = [])706 {707 $parameters['target_project_id'] = $this->id;708 $data = $this->client->mergeRequests()->create(709 $this->id,710 $source,711 $target,712 $title,713 $parameters714 );715 return MergeRequest::fromArray($this->getClient(), $this, $data);716 }717 /**718 * @param int $id719 * @param array $params720 *721 * @return MergeRequest722 */723 public function updateMergeRequest(int $id, array $params)724 {725 $mr = new MergeRequest($this, $id, $this->getClient());726 return $mr->update($params);727 }728 /**729 * @param int $id730 *731 * @return MergeRequest732 */733 public function closeMergeRequest(int $id)734 {735 $mr = new MergeRequest($this, $id, $this->getClient());736 return $mr->close();737 }738 /**739 * @param int $id740 *741 * @return MergeRequest742 */743 public function openMergeRequest(int $id)744 {745 $mr = new MergeRequest($this, $id, $this->getClient());746 return $mr->reopen();747 }748 /**749 * @param int $id750 *751 * @return MergeRequest752 */753 public function mergeMergeRequest(int $id)754 {755 $mr = new MergeRequest($this, $id, $this->getClient());756 return $mr->merge();757 }758 /**759 * @param array $parameters760 *761 * @return Issue[]762 *763 * @see Issues::all() for available parameters.764 */765 public function issues(array $parameters = [])766 {767 $data = $this->client->issues()->all($this->id, $parameters);768 $issues = [];769 foreach ($data as $issue) {770 $issues[] = Issue::fromArray($this->getClient(), $this, $issue);771 }772 return $issues;773 }774 /**775 * @param string $title776 * @param array $params777 *778 * @return Issue779 */780 public function createIssue(string $title, array $params = [])781 {782 $params['title'] = $title;783 $data = $this->client->issues()->create($this->id, $params);784 return Issue::fromArray($this->getClient(), $this, $data);785 }786 /**787 * @param int $iid788 *789 * @return Issue790 */791 public function issue(int $iid)792 {793 $issue = new Issue($this, $iid, $this->getClient());794 return $issue->show();795 }796 /**797 * @param int $iid798 * @param array $params799 *800 * @return Issue801 */802 public function updateIssue(int $iid, array $params)803 {804 $issue = new Issue($this, $iid, $this->getClient());805 return $issue->update($params);806 }807 /**808 * @param int $iid809 * @param string|null $comment810 *811 * @return Issue812 */813 public function closeIssue(int $iid, ?string $comment = null)814 {815 $issue = new Issue($this, $iid, $this->getClient());816 return $issue->close($comment);817 }818 /**819 * @param int $iid820 *821 * @return Issue822 */823 public function openIssue(int $iid)824 {825 $issue = new Issue($this, $iid, $this->getClient());826 return $issue->open();827 }828 /**829 * @param array $parameters830 *831 * @return Milestone[]832 *833 * @see Milestones::all() for available parameters.834 */835 public function milestones(array $parameters = [])836 {837 $data = $this->client->milestones()->all($this->id, $parameters);838 $milestones = [];839 foreach ($data as $milestone) {840 $milestones[] = Milestone::fromArray($this->getClient(), $this, $milestone);841 }842 return $milestones;843 }844 /**845 * @param string $title846 * @param array $params847 *848 * @return Milestone849 */850 public function createMilestone(string $title, array $params = [])851 {852 $params['title'] = $title;853 $data = $this->client->milestones()->create($this->id, $params);854 return Milestone::fromArray($this->getClient(), $this, $data);855 }856 /**857 * @param int $id858 *859 * @return Milestone860 */861 public function milestone(int $id)862 {863 $milestone = new Milestone($this, $id, $this->getClient());864 return $milestone->show();865 }866 /**867 * @param int $id868 * @param array $params869 *870 * @return Milestone871 */872 public function updateMilestone(int $id, array $params)873 {874 $milestone = new Milestone($this, $id, $this->getClient());875 return $milestone->update($params);876 }877 /**878 * @param int $id879 *880 * @return Issue[]881 */882 public function milestoneIssues(int $id)883 {884 $milestone = new Milestone($this, $id, $this->getClient());885 return $milestone->issues();886 }887 /**888 * @return Snippet[]889 */890 public function snippets()891 {892 $data = $this->client->snippets()->all($this->id);893 $snippets = [];894 foreach ($data as $snippet) {895 $snippets[] = Snippet::fromArray($this->getClient(), $this, $snippet);896 }897 return $snippets;898 }899 /**900 * @param string $title901 * @param string $filename902 * @param string $code903 * @param string $visibility904 *905 * @return Snippet906 */907 public function createSnippet(string $title, string $filename, string $code, string $visibility)908 {909 $data = $this->client->snippets()->create($this->id, $title, $filename, $code, $visibility);910 return Snippet::fromArray($this->getClient(), $this, $data);911 }912 /**913 * @param int $id914 *915 * @return Snippet916 */917 public function snippet(int $id)918 {919 $snippet = new Snippet($this, $id, $this->getClient());920 return $snippet->show();921 }922 /**923 * @param int $id924 *925 * @return string926 */927 public function snippetContent(int $id)928 {929 $snippet = new Snippet($this, $id, $this->getClient());930 return $snippet->content();931 }932 /**933 * @param int $id934 * @param array $params935 *936 * @return Snippet937 */938 public function updateSnippet(int $id, array $params)939 {940 $snippet = new Snippet($this, $id, $this->getClient());941 return $snippet->update($params);942 }943 /**944 * @param int $id945 *946 * @return bool947 */948 public function removeSnippet(int $id)949 {950 $snippet = new Snippet($this, $id, $this->getClient());951 return $snippet->remove();952 }953 /**954 * @param int $group_id955 *956 * @return Group957 */958 public function transfer(int $group_id)959 {960 $group = new Group($group_id, $this->getClient());961 return $group->transfer($this->id);962 }963 /**964 * @param int $id965 *966 * @return Project967 */968 public function forkTo(int $id)969 {970 $data = $this->client->projects()->createForkRelation($id, $this->id);971 return self::fromArray($this->getClient(), $data);972 }973 /**974 * @param int $id975 *976 * @return Project977 */978 public function forkFrom(int $id)979 {980 return $this->createForkRelation($id);981 }982 /**983 * @param int $id984 *985 * @return Project986 */987 public function createForkRelation(int $id)988 {989 $data = $this->client->projects()->createForkRelation($this->id, $id);990 return self::fromArray($this->getClient(), $data);991 }992 /**993 * @return bool994 */995 public function removeForkRelation()996 {997 $this->client->projects()->removeForkRelation($this->id);998 return true;999 }1000 /**1001 * @param string $service_name1002 * @param array $params1003 *1004 * @return bool1005 */1006 public function setService(string $service_name, array $params = [])1007 {1008 $this->client->projects()->setService($this->id, $service_name, $params);1009 return true;1010 }1011 /**1012 * @param string $service_name1013 *1014 * @return bool1015 */1016 public function removeService(string $service_name)1017 {1018 $this->client->projects()->removeService($this->id, $service_name);1019 return true;1020 }1021 /**1022 * @return Label[]1023 */1024 public function labels()1025 {1026 $data = $this->client->projects()->labels($this->id);1027 $labels = [];1028 foreach ($data as $label) {1029 $labels[] = Label::fromArray($this->getClient(), $this, $label);1030 }1031 return $labels;1032 }1033 /**1034 * @param string $name1035 * @param string $color1036 *1037 * @return Label1038 */1039 public function addLabel(string $name, string $color)1040 {1041 $data = $this->client->projects()->addLabel($this->id, [1042 'name' => $name,1043 'color' => $color,1044 ]);1045 return Label::fromArray($this->getClient(), $this, $data);1046 }1047 /**1048 * @param string $name1049 * @param array $params1050 *1051 * @return Label1052 */1053 public function updateLabel(string $name, array $params)1054 {1055 if (isset($params['name'])) {1056 $params['new_name'] = $params['name'];1057 }1058 $params['name'] = $name;1059 $data = $this->client->projects()->updateLabel($this->id, $params);1060 return Label::fromArray($this->getClient(), $this, $data);1061 }1062 /**1063 * @param string $name1064 *1065 * @return bool1066 */1067 public function removeLabel(string $name)1068 {1069 $this->client->projects()->removeLabel($this->id, $name);1070 return true;1071 }1072 /**1073 * @return array1074 */1075 public function contributors()1076 {1077 $data = $this->client->repositories()->contributors($this->id);1078 $contributors = [];1079 foreach ($data as $contributor) {1080 $contributors[] = Contributor::fromArray($this->getClient(), $this, $contributor);1081 }1082 return $contributors;1083 }1084 /**1085 * @return Trigger[]1086 */1087 public function triggers()1088 {1089 $data = $this->client->projects()->triggers($this->id);1090 $triggers = [];1091 foreach ($data as $triggerData) {1092 $triggers[] = Trigger::fromArray($this->client, $this, $triggerData);1093 }1094 return $triggers;1095 }1096 /**1097 * @param int $id1098 *1099 * @return Trigger1100 */1101 public function trigger(int $id)1102 {1103 $trigger = new Trigger($this, $id, $this->client);1104 return $trigger->show();1105 }1106 /**1107 * @param string $description1108 *1109 * @return Trigger1110 */1111 public function createTrigger(string $description)1112 {1113 $data = $this->client->projects()->createTrigger($this->id, $description);1114 return Trigger::fromArray($this->client, $this, $data);1115 }1116 /**1117 * @param int $id1118 *1119 * @return Pipeline1120 */1121 public function pipeline(int $id)1122 {1123 $pipeline = new Pipeline($this, $id, $this->client);1124 return $pipeline->show();1125 }1126 /**1127 * @return Pipeline[]1128 */1129 public function pipelines()1130 {1131 $data = $this->client->projects()->pipelines($this->id);1132 $pipelines = [];1133 foreach ($data as $pipelineData) {1134 $pipelines[] = Pipeline::fromArray($this->client, $this, $pipelineData);1135 }1136 return $pipelines;1137 }1138 /**1139 * @param array $scopes1140 *1141 * @return Job[]1142 */1143 public function jobs(array $scopes = [])1144 {1145 $data = $this->client->jobs()->all($this->id, $scopes);1146 $jobs = [];1147 foreach ($data as $job) {1148 $jobs[] = Job::fromArray($this->getClient(), $this, $job);1149 }1150 return $jobs;1151 }1152 /**1153 * @param int $pipeline_id1154 * @param array $scopes1155 *1156 * @return Job[]1157 */1158 public function pipelineJobs(int $pipeline_id, array $scopes = [])1159 {1160 $data = $this->client->jobs()->pipelineJobs($this->id, $pipeline_id, $scopes);1161 $jobs = [];1162 foreach ($data as $job) {1163 $jobs[] = Job::fromArray($this->getClient(), $this, $job);1164 }1165 return $jobs;1166 }1167 /**1168 * @param int $job_id1169 *1170 * @return Job1171 */1172 public function job(int $job_id)1173 {1174 $data = $this->client->jobs()->show($this->id, $job_id);1175 return Job::fromArray($this->getClient(), $this, $data);1176 }1177 /**1178 * @return Badge[]1179 */1180 public function badges()1181 {1182 $data = $this->client->projects()->badges($this->id);1183 $badges = [];1184 foreach ($data as $badge) {1185 $badges[] = Badge::fromArray($this->getClient(), $this, $badge);1186 }1187 return $badges;1188 }1189 /**1190 * @param array $params1191 *1192 * @return Badge1193 */1194 public function addBadge(array $params)1195 {1196 $data = $this->client->projects()->addBadge($this->id, $params);1197 return Badge::fromArray($this->getClient(), $this, $data);1198 }1199 /**1200 * @param int $badge_id1201 * @param array $params1202 *1203 * @return Badge1204 */1205 public function updateBadge(int $badge_id, array $params)1206 {1207 $params['badge_id'] = $badge_id;1208 $data = $this->client->projects()->updateBadge($this->id, $badge_id, $params);1209 return Badge::fromArray($this->getClient(), $this, $data);1210 }1211 /**1212 * @param int $badge_id1213 *1214 * @return bool1215 */1216 public function removeBadge(int $badge_id)1217 {1218 $this->client->projects()->removeBadge($this->id, $badge_id);1219 return true;1220 }1221 /**1222 * @param array $params1223 *1224 * @return Branch1225 */1226 public function addProtectedBranch(array $params = [])1227 {1228 $data = $this->client->projects()->addProtectedBranch($this->id, $params);1229 return Branch::fromArray($this->getClient(), $this, $data);1230 }1231}...
DirtyHookTest.php
Source:DirtyHookTest.php
1<?php2use Crwlr\QueryString\Query;3it('calls the dirty hook when set() was called', function () {4 $query = Query::fromArray(['foo' => 'bar']);5 $hookWasCalled = false;6 $query->setDirtyHook(function () use (& $hookWasCalled) {7 $hookWasCalled = true;8 });9 expect($hookWasCalled)->toBeFalse();10 $query->set('baz', 'quz');11 expect($hookWasCalled)->toBeTrue();12});13it('calls the dirty hook when appendTo() was called', function () {14 $query = Query::fromArray(['foo' => 'bar']);15 $hookWasCalled = false;16 $query->setDirtyHook(function () use (& $hookWasCalled) {17 $hookWasCalled = true;18 });19 expect($hookWasCalled)->toBeFalse();20 $query->appendTo('foo', 'baz');21 expect($hookWasCalled)->toBeTrue();22});23it('calls the dirty hook when remove() was called', function () {24 $query = Query::fromArray(['foo' => 'bar']);25 $hookWasCalled = false;26 $query->setDirtyHook(function () use (& $hookWasCalled) {27 $hookWasCalled = true;28 });29 expect($hookWasCalled)->toBeFalse();30 $query->remove('foo');31 expect($hookWasCalled)->toBeTrue();32});33it('calls the dirty hook when removeValueFrom() was called', function () {34 $query = Query::fromArray(['foo' => ['1', '2']]);35 $hookWasCalled = false;36 $query->setDirtyHook(function () use (& $hookWasCalled) {37 $hookWasCalled = true;38 });39 expect($hookWasCalled)->toBeFalse();40 $query->removeValueFrom('foo', '2');41 expect($hookWasCalled)->toBeTrue();42});43it('calls the dirty hook when filter() was called', function () {44 $query = Query::fromArray(['1', '2', '3', '4', '5']);45 $hookWasCalled = false;46 $query->setDirtyHook(function () use (& $hookWasCalled) {47 $hookWasCalled = true;48 });49 expect($hookWasCalled)->toBeFalse();50 $query->filter(function ($value) {51 return (int) $value > 2;52 });53 expect($hookWasCalled)->toBeTrue();54});55it('calls the dirty hook when map() was called', function () {56 $query = Query::fromArray(['1', '2', '3', '4', '5']);57 $hookWasCalled = false;58 $query->setDirtyHook(function () use (& $hookWasCalled) {59 $hookWasCalled = true;60 });61 expect($hookWasCalled)->toBeFalse();62 $query->map(function ($value) {63 return (int) $value + 1;64 });65 expect($hookWasCalled)->toBeTrue();66});67it('calls the dirty hook when boolToString() was called', function () {68 $query = Query::fromArray(['foo' => true, 'bar' => false]);69 $hookWasCalled = false;70 $query->setDirtyHook(function () use (& $hookWasCalled) {71 $hookWasCalled = true;72 });73 expect($hookWasCalled)->toBeFalse();74 $query->boolToString();75 expect($hookWasCalled)->toBeTrue();76});77it('calls the dirty hook when boolToInt() was called', function () {78 $query = Query::fromArray(['foo' => true, 'bar' => false]);79 $hookWasCalled = false;80 $query->setDirtyHook(function () use (& $hookWasCalled) {81 $hookWasCalled = true;82 });83 expect($hookWasCalled)->toBeFalse();84 $query->boolToString();85 $query->boolToInt();86 expect($hookWasCalled)->toBeTrue();87});88it('calls the dirty hook when spaceCharacterPercentTwenty() was called', function () {89 $query = Query::fromArray(['foo' => 'spa ce']);90 $hookWasCalled = false;91 $query->setDirtyHook(function () use (& $hookWasCalled) {92 $hookWasCalled = true;93 });94 expect($hookWasCalled)->toBeFalse();95 $query->spaceCharacterPercentTwenty();96 expect($hookWasCalled)->toBeTrue();97});98it('calls the dirty hook when spaceCharacterPlus() was called', function () {99 $query = Query::fromArray(['foo' => 'spa ce']);100 $hookWasCalled = false;101 $query->setDirtyHook(function () use (& $hookWasCalled) {102 $hookWasCalled = true;103 });104 expect($hookWasCalled)->toBeFalse();105 $query->spaceCharacterPercentTwenty();106 $query->spaceCharacterPlus();107 expect($hookWasCalled)->toBeTrue();108});109it('calls the dirty hook when separator() was called', function () {110 $query = Query::fromArray(['foo' => '1', 'bar' => '2']);111 $hookWasCalled = false;112 $query->setDirtyHook(function () use (& $hookWasCalled) {113 $hookWasCalled = true;114 });115 expect($hookWasCalled)->toBeFalse();116 $query->separator(';');117 expect($hookWasCalled)->toBeTrue();118});119it('calls the dirty hook when something in a child Query instance was changed', function () {120 $query = Query::fromArray(['foo' => ['bar' => 'baz']]);121 $hookWasCalled = false;122 $query->setDirtyHook(function () use (& $hookWasCalled) {123 $hookWasCalled = true;124 });125 expect($hookWasCalled)->toBeFalse();126 $query->get('foo')->set('quz', 'test');127 expect($hookWasCalled)->toBeTrue();128});...
fromArray
Using AI Code Generation
1$hook = new Hook();2$hook->fromArray(array(3));4$hook->save();5$hook = new Hook();6$hook->fromArray(array(7));8$hook->save();9$hook = new Hook();10$hook->fromArray(array(11));12$hook->save();13$hook = new Hook();14$hook->fromArray(array(15));16$hook->save();17$hook = new Hook();18$hook->fromArray(array(19));20$hook->save();
fromArray
Using AI Code Generation
1$hook = new Hook();2$hook->fromArray(array('name' => 'test'));3echo $hook->getName();4$hook = new Hook();5$hook->fromArray(array('name' => 'test'));6echo $hook->getName();7$hook = new Hook();8$hook->fromArray(array('name' => 'test'));9echo $hook->getName();10$hook = new Hook();11$hook->fromArray(array('name' => 'test'));12echo $hook->getName();
fromArray
Using AI Code Generation
1$hook = new Hook();2$hook->fromArray(array('class' => 'MyClass', 'function' => 'myFunction', 'file' => 'somefile.php', 'type' => 'action', 'active' => 1));3$hook->save();4$hook = new Hook();5$hook->fromArray(array('class' => 'MyClass', 'function' => 'myFunction', 'file' => 'somefile.php', 'type' => 'action', 'active' => 1));6$hook->save();7$hook = new Hook();8$hook->fromArray(array('class' => 'MyClass', 'function' => 'myFunction', 'file' => 'somefile.php', 'type' => 'action', 'active' => 1));9$hook->save();10$hook = new Hook();11$hook->fromArray(array('class' => 'MyClass', 'function' => 'myFunction', 'file' => 'somefile.php', 'type' => 'action', 'active' => 1));12$hook->save();13$hook = new Hook();14$hook->fromArray(array('class' => 'MyClass', 'function' => 'myFunction', 'file' => 'somefile.php', 'type' => 'action', 'active' => 1));15$hook->save();16$hook = new Hook();17$hook->fromArray(array('class' => 'MyClass', 'function' => 'myFunction', 'file' => 'somefile.php', 'type' => 'action', 'active' => 1));18$hook->save();19$hook = new Hook();20$hook->fromArray(array('class' => 'MyClass', 'function' => 'myFunction', 'file' => 'somefile.php', 'type' => 'action', 'active' => 1));
fromArray
Using AI Code Generation
1$hook = new Hook();2$hook->fromArray(array('name' => 'test', 'description' => 'test hook'));3$hook->save();4$group = new Group();5$group->fromArray(array('name' => 'test', 'description' => 'test group'));6$group->save();7$user = new User();8$user->fromArray(array('user_name' => 'test', 'first_name' => 'test', 'last_name' => 'test', 'status' => 'Active', 'is_admin' => 0, 'email' => '
fromArray
Using AI Code Generation
1require_once('Hook.php');2$hook = new Hook();3$hook->fromArray(array('name'=>'Brijesh','age'=>23));4echo $hook->name;5echo $hook->age;6require_once('Hook.php');7$hook = new Hook();8$hook->fromArray(array('name'=>'Brijesh','age'=>23));9$hook->fromArray(array('name'=>'Brijesh','age'=>23,'address'=>'xyz'));10echo $hook->name;11echo $hook->age;12echo $hook->address;13require_once('Hook.php');14$hook = new Hook();15$hook->fromArray(array('name'=>'Brijesh','age'=>23));16$hook->fromArray(array('name'=>'Brijesh','age'=>23,'address'=>'xyz'));17echo $hook->name;18echo $hook->age;19echo $hook->address;20require_once('Hook.php');21$hook = new Hook();22$hook->fromArray(array('name'=>'Brijesh','age'=>23));23$hook->fromArray(array('name'=>'Brijesh','age'=>23,'address'=>'xyz'));24echo $hook->name;25echo $hook->age;26echo $hook->address;27echo $hook->salary;28require_once('Hook.php');29$hook = new Hook();30$hook->fromArray(array('name'=>'Brijesh','age'=>23));31$hook->fromArray(array('name'=>'Brijesh','age'=>23,'address'=>'xyz'));32echo $hook->name;33echo $hook->age;34echo $hook->address;35echo $hook->salary;36echo $hook->city;37require_once('Hook.php');38$hook = new Hook();39$hook->fromArray(array('name'=>'Brijesh','age'=>23));40$hook->fromArray(array('name'=>'Brijesh','age'=>23,'address'=>'xyz'));41echo $hook->name;42echo $hook->age;43echo $hook->address;44echo $hook->salary;
fromArray
Using AI Code Generation
1$hook = new Hook();2$hook->fromArray($_POST);3$hook->setVar('hook_id', $hook->getVar('hook_id'));4$hook->setVar('hook_name', $hook->getVar('hook_name'));5$hook->setVar('hook_file', $hook->getVar('hook_file'));6$hook->setVar('hook_function', $hook->getVar('hook_function'));7$hook->setVar('hook_type', $hook->getVar('hook_type'));8$hook->setVar('hook_order', $hook->getVar('hook_order'));9$hook->setVar('hook_active', $hook->getVar('hook_active'));10$hook->setVar('hook_module', $hook->getVar('hook_module'));11$hook->setVar('hook_code', $hook->getVar('hook_code'));12$hook->setVar('hook_description', $hook->getVar('hook_description'));13$hook->setVar('hook_example', $hook->getVar('hook_example'));14$hook->setVar('hook_version', $hook->getVar('hook_version'));15$hook->setVar('hook_author', $hook->getVar('hook_author'));16$hook->setVar('hook_email', $hook->getVar('hook_email'));17$hook->setVar('hook_website', $hook->getVar('hook_website'));18$hook->setVar('hook_license', $hook->getVar('hook_license'));19$hook->setVar('hook_image', $hook->getVar('hook_image'));20$hook->setVar('hook_image_width', $hook->getVar('hook_image_width'));21$hook->setVar('hook_image_height', $hook->getVar('hook_image_height'));22$hook->setVar('hook_image_alt', $hook->getVar('hook_image_alt'));23$hook->setVar('hook_image_title', $hook->getVar('hook_image_title'));24$hook->setVar('hook_image_url', $hook->getVar('hook_image_url'));25$hook->setVar('hook_image_link', $hook->getVar('hook_image_link'));26$hook->setVar('hook_image_target', $hook->getVar('hook_image_target'));27$hook->setVar('hook_image_css', $hook->getVar('hook_image_css'));28$hook->setVar('hook_image_js', $hook->getVar('hook_image_js'));29$hook->setVar('hook_image_onclick', $hook->getVar
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with fromArray on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!