Skip to content

Commit

Permalink
Issue #15 - record more information for components
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbingwide committed Mar 11, 2018
1 parent e4f1ffb commit 13c05d0
Show file tree
Hide file tree
Showing 8 changed files with 2,765 additions and 3,164 deletions.
25 changes: 18 additions & 7 deletions converter/class-component-counter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,38 @@ class component_counter {

public $components;

/**
* Constructor for component_counter
*/
public function __construct() {
$this->components = array();
$this->components['plugins'] = array();
$this->components['themes'] = array();
}

public function add( $component, $type ) {
/**
* Adds a component or increments the count of times found
*
*/
public function add( $component, $type, $path ) {
if ( !isset( $this->components[ $type ][ $component ] ) ) {
$this->components[ $type ][ $component ] = 0;
$this->components[ $type ][ $component ] = new Component( $component, $type, $path);
}
$this->components[ $type ][ $component ] += 1;
$this->components[ $type ][ $component ]->add();
}



/**
* Reports the counts and other information for each component
*/
public function report() {
//print_r( $this->components );
echo "Type,Component,Count" . PHP_EOL;
echo "Type,Component,Count,Author,Third Party,Tests" . PHP_EOL;
$components = 0;
$total = 0;
foreach ( $this->components as $type => $data ) {
foreach ( $data as $component => $count ) {
echo "$type,$component,$count" . PHP_EOL;
foreach ( $data as $component => $component_object ) {
$count = $component_object->report();
$total += $count;
$components++;
}
Expand Down
103 changes: 103 additions & 0 deletions converter/class-component.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php

/**
* @copyright (C) Bobbing Wide 2018
* @package oik-block
*/

class component {

public $component;
public $type;
public $path;
public $count;
public $author;
public $third_party;
public $tests;

public function __construct( $component, $type, $path ) {
$this->component = $component;
$this->type = $type;
$this->path = $path;
$this->count = 0;
$this->author = "";
$this->third_party = true;
$this->tests = false;
//if ( $this->type == "plugins" ) {
$this->is_author_bobbingwide();
//}
if ( $this->third_party ) {
$this->set_third_party();
}
$this->set_tests();

}

public function add() {
$this->count++;
}

/**
* Tests if it's a third party plugin
*
* - If this is one of our repo's it may not be a third party plugin or theme
* - If there is both a README.md and readme.txt
* - It would be better to determine who the contributors are from get_plugin_data()
*
*
*/
function set_third_party() {
$myrepo = "C:/github/bobbingwide/{$this->component}";
if ( file_exists( $myrepo ) ) {
if ( file_exists( "$myrepo/README.md" ) && file_exists( "$myrepo/readme.txt" ) ) {
//print_r( $this );
$this->third_party = false;
//gob();
}
}

}

/**
* Sets third_party false if author is bobbingwide
*/
function is_author_bobbingwide() {
$plugin = array();
$plugin[] = $this->path;
$plugin[] = $this->component;
$plugin[] = $this->component . ".php";
$plugin_file = implode( "/", $plugin );

if ( file_exists( $plugin_file ) ) {
$plugin_data = get_plugin_data( $plugin_file, false, false );
if ( $plugin_data ) {
$author = bw_array_get( $plugin_data, "Author", true );
$this->author = str_replace( ",", "", $author );
}
}
}

function set_tests() {
$test_dir ="{$this->path}/{$this->component}/tests";
//echo $test_dir;
if ( file_exists( $test_dir ) ) {
$this->tests = true;
}
}

function report() {
$report = array();
$report[] = $this->type;
$report[] = $this->component;
$report[] = $this->count;
$report[] = $this->author;
$report[] = $this->third_party;
$report[] = $this->tests;
$report[] = $this->path;
$line = implode( ",", $report );
echo $line . PHP_EOL;
return $this->count;
}


}

0 comments on commit 13c05d0

Please sign in to comment.