Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
5 / 5
ActorArrayTransformer
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
5 / 5
 transform
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 reverseTransform
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
1<?php
2
3// {{{ License
4
5// This file is part of GNU social - https://www.gnu.org/software/social
6//
7// GNU social is free software: you can redistribute it and/or modify
8// it under the terms of the GNU Affero General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// GNU social is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15// GNU Affero General Public License for more details.
16//
17// You should have received a copy of the GNU Affero General Public License
18// along with GNU social.  If not, see <http://www.gnu.org/licenses/>.
19
20// }}}
21
22/**
23 * Transform between string and list of typed profiles
24 *
25 * @package  GNUsocial
26 * @category Form
27 *
28 * @author    Hugo Sales <hugo@hsal.es>
29 * @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org
30 * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
31 */
32
33namespace App\Util\Form;
34
35use App\Entity\GSActor;
36
37class ActorArrayTransformer extends ArrayTransformer
38{
39    /**
40     * Transforms array of GSActors into string of usernames
41     *
42     * @param array $a
43     *
44     * @return string
45     */
46    public function transform($a)
47    {
48        return parent::transform(array_map(
49            function ($actor) { return $actor->getNickname(); },
50            $a)
51        );
52    }
53
54    /**
55     * Transforms string of usernames into GSActors
56     *
57     * @param string $s
58     *
59     * @return array
60     */
61    public function reverseTransform($s)
62    {
63        return array_map(
64            function ($nickmame) { return GSActor::getFromNickname($nickmame); },
65            parent::reverseTransform($s)
66        );
67    }
68}