为什么我没有使用循环表的预期结果?

I am creating a code complexity measuring tool for a academic purpose. this is the method function. all the method return type,primitive data type parameters,composite data type parameters are awarded 1 point. complexity due to method is the addition of the earlier mentioned points.all these things divided into columns of a table. (i tried to summarized the specification as much as i can. please if it is not clear check this link. it is a half a page specification for this function https://gofile.io/d/Xme6Cb). i implemented the method function but i am getting wrong points in the tables. can someone please suggest what i should do. i m sorry the code is bit long and i tried to keep it to the minimal but i can't find out where the exact problem is. I have commented // -------- Weight due to return type - Begin -------- when i commented this loop i am getting 0 for all the columns. but when i uncomment this i am getting unexpected points for the table. i tried to fix this. but i had no luck. can someone please suggest me what i should do, and i am sorry if i couldn't keep the question to the minimal. i am stuck with this, any help is appreciated. Thank you!

<?php

if (!isset($_GET['reload'])) {
    echo '<meta http-equiv=Refresh content="0;url=methods.php?reload=1">';
}

?>

<?php include 'include/header.php'; ?>
<?php include 'include/aside.php'; ?>

<?php $split = $_SESSION['split_code']; ?>

<div class="kt-content  kt-grid__item kt-grid__item--fluid kt-grid kt-grid--hor" id="kt_content">

                        <!-- begin:: Content Head -->
                        <div class="kt-subheader  kt-grid__item" id="kt_subheader">
                            <div class="kt-container  kt-container--fluid ">
                                <div class="kt-subheader__main">
                                    <h3 class="kt-subheader__title">Methods Complexity of the Program</h3>
                                    <span class="kt-subheader__separator kt-subheader__separator--v"></span>


                                    <div class="kt-input-icon kt-input-icon--right kt-subheader__search kt-hidden">
                                        <input type="text" class="form-control" placeholder="Search order..." id="generalSearch">
                                        <span class="kt-input-icon__icon kt-input-icon__icon--right">
                                            <span><i class="flaticon2-search-1"></i></span>
                                        </span>
                                    </div>
                                </div>
                                <div class="kt-subheader__toolbar">





                                </div>
                            </div>
                        </div>

                        <!-- end:: Content Head -->

                        <!-- begin:: Content -->
                        <div class="kt-container  kt-container--fluid  kt-grid__item kt-grid__item--fluid">
                            <!--Begin::Dashboard 3-->
<!--Begin::Row-->
<div class="row">






    <!--begin::Portlet-->
    <div style="background-color: #f8f5f4;" class="kt-portlet kt-portlet--skin-solid kt-portlet--">
        <div class="kt-portlet__head">
            <div class="kt-portlet__head-label">
                                                <span class="kt-portlet__head-icon kt-font-brand">
                                                    <i class="flaticon-time-1"></i>
                                                </span>
                <h3 class="kt-portlet__head-title kt-font-brand">
                    Complexity of the Program due to Methods
                </h3>
            </div>

        </div>
        <div class="kt-portlet__body kt-font-brand">


            <div class="row">

                <div class="col-lg-12">
                    <div class="kt-portlet kt-iconbox kt-iconbox--brand ">
                        <div class="kt-portlet__body">
                            <div class="kt-iconbox__body">
                                <div class="col-lg-12">
                                <div class="kt-iconbox__desc kt-font-brand">

                                    <center><h1 style="font-family: 'Fira Code'">Cm : <?php echo $total_Cm = $_SESSION['total_Cm']; ?>
                                        </h1></center>


                                </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>



        </div>

        <div class="kt-portlet__foot">
            <div class="kt-form__actions">
                <div class="row">


                    <!-- begin:: Content -->
                    <div class="kt-container  kt-container--fluid  kt-grid__item kt-grid__item--fluid">

                        <div class="kt-portlet kt-portlet--mobile">
                            <div class="kt-portlet__head kt-portlet__head--lg">
                                <div class="kt-portlet__head-label">
                                        <span class="kt-portlet__head-icon">
                                            <i class="kt-font-brand flaticon2-line-chart"></i>
                                        </span>
                                    <h3 class="kt-portlet__head-title kt-font-brand">
                                        Complexity of the Program due to the Methods by Statement : </h3>&nbsp;
                                    <h3 class="kt-portlet__head-title kt-font-dark"><?php $file = $_SESSION['filename'];
                                        echo $file; ?>
                                    </h3>
                                </div>
                            </div>

                            <div class="kt-portlet__body kt-font-dark">
                                <!--begin: Datatable -->
                                <table style="font-family: 'Fira Code'; text-align: center" class="table table-striped- table-bordered table-hover" id="kt_table_1">
                                    <thead>
                                    <tr class="kt-label-bg-color-1" style="font-family: 'Fira Code Medium'">
                                        <th>Line No</th>
                                        <th>Program Statements</th>
                                        <th>Wmrt</th>
                                        <th>Npdtp</th>
                                        <th>Ncdtp</th>
                                        <th style="color: white" class="kt-label-bg-color-2">Cm</th>


                                    </tr>
                                    </thead>
                                    <tbody>

                                    <?php

                                    $i = 0; //increment to each loop
                                    $count = 0;
                                    $total_Cm = 0;

                                    $Wmrt = 0;
                                    $Npdtp = 0;
                                    $Ncdtp = 0;
                                    $Cm = 0;

                                    //Default Weights
                                    $weight_primitive_retuntype = 1;
                                    $weight_composite_returntype = 2;
                                    $weight_void_returntype = 0;
                                    $weight_primitive_datatype_parameter = 1;
                                    $weight_composite_datatype_parameter = 2;

                                    if (!$split==""){
                                    foreach($split AS $val) { // Traverse the array with FOREACH

                                    $val;

                                    // -------- Weight due to return type - Begin --------

                                    $void_count_total = 0;
                                    $primitive_retuntype_count_total = 0;
                                    $composite_retuntype_count_total = 0;

                                    // for($x = 0; $x <= $row_count; $x++){

                                    //     if (preg_match('/void+(.*?){/', $val) !== false ){

                                    //         $void_count_total = preg_match_all('/void+(.*?){/',$val,$counter);

                                    //     }

                                    //     if (preg_match('/(?:(?:public|private|protected|static|final|native|synchronized|abstract|transient)+\s)+(int|byte|short|long|float|double|char|String|boolean)+[$_\w<>\[\]\s]*\s+[\$_\w]+\([^\)]*\)?\s*\{?[^\}]+return +(.*?)+\}?/', $val) !== false ){

                                    //         $primitive_retuntype_count_total = preg_match_all('/(?:(?:public|private|protected|static|final|native|synchronized|abstract|transient)+\s)+(int|byte|short|long|float|double|char|String|boolean)+[$_\w<>\[\]\s]*\s+[\$_\w]+\([^\)]*\)?\s*\{?[^\}]+return +(.*?)+\}?/',$val,$counter);

                                    //     }

                                    //     if (preg_match('//', $val) !== false ){

                                    //         $composite_retuntype_count_total = preg_match_all('//',$val,$counter);

                                    //     }


                                    //     $Wmrt = ($void_count_total*$weight_void_returntype) + ($primitive_retuntype_count_total*$weight_primitive_retuntype) + ($composite_retuntype_count_total*$weight_composite_returntype);

                                    // }

                                    // -------- Weight due to return type - End --------

                                    $Cm = $Wmrt + $Npdtp + $Ncdtp;

                                    $total_Cm += $Cm;

                                    ?>

                                    <tr>
                                        <td><?php echo ++$count; ?></td>
                                        <td style="text-align: left"><?php echo $val;?></td>
                                        <td><?php echo $Wmrt; ?></td>
                                        <td><?php echo $Npdtp; ?></td>
                                        <td><?php echo $Ncdtp; ?></td>
                                        <td><?php echo $Cm; ?></td>
                                        <?php

                                        $i++;

                                        $_SESSION['total_Cm'] = $total_Cm;

                                        }

                                        }
                                        ?>
                                    </tr>


                                    </tbody>

                                </table>

                                <!--end: Datatable -->
                            </div>
                        </div>
                    </div>

                    <!-- end:: Content -->








                </div></div></div>

                <div class="kt-portlet__foot">
                    <div class="kt-form__actions">
                        <div class="row">



                    <div class="col-lg-12 ml-lg-auto">
                        <center>

                            <a href="total_weight.php"><button type="button" href="total_weight.php" class="btn btn-brand"><span><i class="flaticon-home"></i></span> Total Complexity of the Program</button></a>
                        </center>
                    </div>
                </div>
            </div>
        </div>
    </div>
        </div>
    <!--end::Portlet-->





</div>


                            <!--End::Row-->

                            <!--End::Dashboard 3-->
                        </div>
                        <!-- end:: Content -->
                    </div>


<?php include 'include/footer.php'; ?>
评论