<commit_before><?php
/**
 * Client module for HiPanel
 *
 * @link      https://github.com/hiqdev/hipanel-module-client
 * @package   hipanel-module-client
 * @license   BSD-3-Clause
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
 */

namespace hipanel\modules\client\forms;

use hipanel\modules\client\models\Contact;
use hipanel\modules\document\models\Document;
use hiqdev\hiart\Collection;
use hiqdev\hiart\ResponseErrorException;
use Yii;

/**
 * Class EmployeeForm represents form for employee management.
 */
class EmployeeForm
{
    /**
     * Default contact language.
     */
    const LANGUAGE_DEFAULT = 'en';

    /**
     * @var array Available contact languages
     */
    protected $languages = [self::LANGUAGE_DEFAULT, 'uk'];

    /**
     * @var Contact[] contacts available for editing
     */
    protected $contacts = [];

    /**
     * @var string the scenario that will be used for all models
     */
    protected $scenario;

    /**
     * @var Document the contract
     */
    protected $contract;

    /**
     * @param Contact $contact
     * @param $scenario
     */
    public function __construct(Contact $contact, $scenario)
    {
        $this->scenario = $scenario;
        $this->contacts = $this->extractContacts($contact);
        if (Yii::$app->user->can('document.read')) {
            $this->contract = $this->extractContract($contact);
        }
    }

    /**
     * Extracts all the contacts available in the $contact model.
     *
     * @param Contact $contact
     * @return array
     */
    protected function extractContacts(Contact $contact)
    {
        $result = [];

        foreach ($this->languages as $language) {
            $result[$language] = $this->contactLocalization($contact, $language);
        }

        return $result;
    }

    /**
     * Extracts contract out of documents array.
     *
     * @param Contact $contact<commit_msg>Fix PHP Warning<commit_after><?php
/**
 * Client module for HiPanel
 *
 * @link      https://github.com/hiqdev/hipanel-module-client
 * @package   hipanel-module-client
 * @license   BSD-3-Clause
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
 */

namespace hipanel\modules\client\forms;

use hipanel\modules\client\models\Contact;
use hipanel\modules\document\models\Document;
use hiqdev\hiart\Collection;
use hiqdev\hiart\ResponseErrorException;
use Yii;

/**
 * Class EmployeeForm represents form for employee management.
 */
class EmployeeForm
{
    /**
     * Default contact language.
     */
    const LANGUAGE_DEFAULT = 'en';

    /**
     * @var array Available contact languages
     */
    protected $languages = [self::LANGUAGE_DEFAULT, 'uk'];

    /**
     * @var Contact[] contacts available for editing
     */
    protected $contacts = [];

    /**
     * @var string the scenario that will be used for all models
     */
    protected $scenario;

    /**
     * @var Document the contract
     */
    protected $contract;

    /**
     * @param Contact $contact
     * @param $scenario
     */
    public function __construct(Contact $contact, $scenario = 'default')
    {
        $this->scenario = $scenario;
        $this->contacts = $this->extractContacts($contact);
        if (Yii::$app->user->can('document.read')) {
            $this->contract = $this->extractContract($contact);
        }
    }

    /**
     * Extracts all the contacts available in the $contact model.
     *
     * @param Contact $contact
     * @return array
     */
    protected function extractContacts(Contact $contact)
    {
        $result = [];

        foreach ($this->languages as $language) {
            $result[$language] = $this->contactLocalization($contact, $language);
        }

        return $result;
    }

    /**
     * Extracts contract out of documents array.
     *
     * @param Contact $contact
{'fraction_non_alphanumeric': 0.13089683773976155, 'fraction_numerical': 0.004665629860031105, 'mean_word_length': 2.4547896150402866, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6407819', 'n_tokens_mistral': 1143, 'n_tokens_neox': 1117, 'n_words': 272}