<commit_before><?php

namespace Applicazza\Appointed;

use Carbon\Carbon;
use InvalidArgumentException;
use SplDoublyLinkedList;

/**
 * Class BusinessDay
 * @package Applicazza\Appointed
 */
class BusinessDay
{
    /**
     * @var \Applicazza\Appointed\Period[]
     */
    protected $business_hours = [];

    /**
     * @var \Applicazza\Appointed\Period[]
     */
    protected $occupied_slots = [];

    /**
     * @var \SplDoublyLinkedList
     */
    protected $slots;

    /**
     * BusinessDay constructor.
     */
    function __construct()
    {
        $this->slots = new SplDoublyLinkedList;
    }

    /**
     * @param array ...$business_hours
     * @return static
     */
    public function addBusinessHours(... $business_hours)
    {
        $pending_business_hours = [];

        foreach ($business_hours as $business_hour_period) {

            if (!is_object($business_hour_period) || get_class($business_hour_period) !== Period::class)
                throw new InvalidArgumentException();

            $pending_business_hours[] = $business_hour_period;
        }

        if (count($pending_business_hours)) {

            $this->business_hours = array_merge($this->business_hours, $pending_business_hours);

            $this->sortBusinessHours();

            $this->rebuild();

        }

        return $this;
    }

    /**
     * @return \Applicazza\Appointed\Period[]
     */
    public function getBusinessHours()
    {
        return $this->business_hours;
    }

    /**
     * @return \Applicazza\Appointed\Period[]
     */
    public function getOccupiedSlots()
    {
        return $this->occupied_slots;
    }

    /**
     * @return string
     */
    public function getOccupiedSlotsAsJson()
    {
        return json_encode($this->occupied_slots);
    }

    /**
     * @param array ...$occupied_slots
     * @return static
     */
    public function addOccupiedSlots(... $occupied_slots)
    {
        $pending_occupied_slots = [];

        foreach ($occupied_slots as $occupied_slot) {

            if (!is_object($occupied_slot) || get_class($occupied_slot) !== Period::class)
                throw new InvalidArgumentException();

            $pending_occupied_slots[] = $occupied_slot;
        }

        if (count($pending_occupied_slots)) {

            $this->occupied_slots = array_merge($this->occupied_slots, $pending_occupied_slots);

            $this->sortOccupiedSlots();

            $this->rebuild();

        }

        return $this;
    }<commit_msg>Fixed getOccupiedSlotsAsJson meethod Added getBusinessHoursAsJson method<commit_after><?php

namespace Applicazza\Appointed;

use Carbon\Carbon;
use InvalidArgumentException;
use SplDoublyLinkedList;

/**
 * Class BusinessDay
 * @package Applicazza\Appointed
 */
class BusinessDay
{
    /**
     * @var \Applicazza\Appointed\Period[]
     */
    protected $business_hours = [];

    /**
     * @var \Applicazza\Appointed\Period[]
     */
    protected $occupied_slots = [];

    /**
     * @var \SplDoublyLinkedList
     */
    protected $slots;

    /**
     * BusinessDay constructor.
     */
    function __construct()
    {
        $this->slots = new SplDoublyLinkedList;
    }

    /**
     * @param array ...$business_hours
     * @return static
     */
    public function addBusinessHours(... $business_hours)
    {
        $pending_business_hours = [];

        foreach ($business_hours as $business_hour_period) {

            if (!is_object($business_hour_period) || get_class($business_hour_period) !== Period::class)
                throw new InvalidArgumentException();

            $pending_business_hours[] = $business_hour_period;
        }

        if (count($pending_business_hours)) {

            $this->business_hours = array_merge($this->business_hours, $pending_business_hours);

            $this->sortBusinessHours();

            $this->rebuild();

        }

        return $this;
    }

    /**
     * @return \Applicazza\Appointed\Period[]
     */
    public function getBusinessHours()
    {
        return $this->business_hours;
    }

    /**
     * @return string
     */
    public function getBusinessHoursAsJson()
    {

        $business_hours = [];
        foreach ($this->business_hours as $business_hour) {
            $business_hours[] = (string) $business_hour;
        }

        return json_encode($business_hours, JSON_PRETTY_PRINT);
    }

    /**
     * @return \Applicazza\Appointed\Period[]
     */
    public function getOccupiedSlots()
    {
        return $this->occupied_slots;
    }

    /**
     * @return string
     */
    public function getOccupiedSlotsAsJson()
    {
        $occupied_slots = [];
        foreach ($this->occupied_slots as $occupied_slot) {
            $occupied_slots[] = (string) $occupied_slot;
        }

        return json_encode($occupied_slots, JSON_PRETTY_PRINT);
    }

    /**
     * @param array ...$occupied_slots
     * @return static
     */
    public function addOccupiedSlots(... $occupied_slots)
    {
        $pending_occupied_slots = [];

        foreach ($occupied_slots as $occupied_slot) {

            if (!is_object($occupied_slot) || get_class($occupied_slot) !== Period::class)
                throw new InvalidArgumentException();

            $pending_occupied_slots[] = $occupied_slot;
        }

        if (count($pending_occupied_slots)) {

            $this->occupied_slots = array_merge($this->occupied_slots, $pending_occupied_slots);

            $this->sortOccupiedSlots();

            $this->rebuild();

        }

        return $this;
    }
{'fraction_non_alphanumeric': 0.12439418416801293, 'fraction_numerical': 0.0, 'mean_word_length': 2.233894370284388, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, 'https://': 0, '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': '5406283', 'n_tokens_mistral': 1788, 'n_tokens_neox': 1632, 'n_words': 268}